InvalidcastException in BitMap call

  • Thread starter Thread starter HW
  • Start date Start date
H

HW

Hi, I'm creating BitMap as follows

bmp = New BitMap("Program Files\1.png")

This is causing a Invalid cast Exception, call stack suggests its in the
_InitFromStream method. What is wrong with the above???
 
You need a slash in front of program files ie:

bmp = New BitMap("\Program Files\1.png")

Regards
Simon.
 
Hi Simon, sorry that was a typo i do have a slash

bmp = New BitMap("\Program Files\1.png")

In the debugger this throws an InvalidCastException, the file
is valid and a bitmap does get created but why this exception in the
debugger?
 
Well the exception is handled internally by one of the class libraries, it
can be seen only by
enabling exceptions in the debugger, ie the only reason i can spot it is
because
the debugger catches all exceptions including those that have been thrown
and handled by the class library in framework.

As mentioned in my first post, the actual method where the exception is
raised
is the InitFromStream method presumably the file path passed to the Bitmap
constructor
call is being coverted to stream somewhere. Anyway i have found in the past
these
sort of exceptions can be cleared by passing in the absolute correct
parameters.
 
Back
Top