InvalidcastException in BitMap call

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???
 
S

Simon Hart

You need a slash in front of program files ie:

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

Regards
Simon.
 
H

HW

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?
 
H

HW

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top