complie Errors

  • Thread starter Thread starter Roger Vale
  • Start date Start date
R

Roger Vale

Hi all

Visual studio 2005
Visual Basic
windows mobile application

I am getting this from the imediate window A first chance exception of type
'System.InvalidCastException' occurred in System.Drawing.dll

Now the program still runs but this error seems to appear every time i swap
an image from a file

Code i am using is as follows

Dim leftImage As Bitmap


leftImage = New Bitmap(boardImagesPath +
CStr(boardPositionP1 - 1) + ".jpg")
leftPb.Image = leftImage


I dont know if this is enough information any help would be great

Thanks in advance

Roger
 
You may see this message at when you 'debug' the project in the IDE, but you
will never see it when you compile a project.

When an application is being debugged, the debugger gets notified whenever
an exception is encountered At this point, the application is suspended and
the debugger decides how to handle the exception. The first pass through
this mechanism is called a "first chance" exception. Depending on the
debugger's configuration, it will either resume the application and pass the
exception on or it will leave the application suspended and enter debug
mode. If the application handles the exception, it continues to run
normally.

If the application does not handle the exception, the debugger is
re-notified. This is known as a "second chance" exception. The debugger
again suspends the application and determines how to handle this exception.
Typically, debuggers are configured to stop on second chance (unhandled)
exceptions and debug mode is entered, allowing you to debug.

First chance exception messages most often do not mean there is a problem in
the code. For applications / components which handle exceptions gracefully,
first chance exception messages let the developer know that an exceptional
situation was encountered and was handled.

For code without exception handling, the debugger will receive a second
chance exception notification and will stop with a unhandled exception.

Because you are not getting an unhandled exception, (or if you are you
haven't said so), then you must have some exception handling code that you
ommitted from your post. If that is the case then you have nothing to worry
about.

By the way, are you aware that you can simply that piece of code to:

leftPb.Load(boardImagesPath + CStr(boardPositionP1 - 1) + ".jpg")

or, even better:

leftPb.Load(boardImagesPath & CStr(boardPositionP1 - 1) & ".jpg")
 
Thanks for the reply

I am not getting a unhandled reply and i have read that this will not cause
a problem when not running in debug mode.
But it does slow down the application while it runs in debug mode
is there any way to prevent this?

and thanks for the coding advice I did have the code the way you suggested
but have changed it arround to try and remove this first chance error
 
What slows down the application while it runs in debug mode is the fact that
you're running it in debug mode in the IDE.
 
You are loading a bitmap which is fine but the .Image property is of type
Image, try to DirectCast leftImage and the error should go away.
Alternatively (as Stephany pointed out) you can use Load() which takes the
string as a parameter. I doubt that method would result in the same
warning.

leftPb.Image = DirectCast(New Bitmap(boardImagesPath +
CStr(boardPositionP1 - 1) + ".jpg"), Image)

Tom
 
thanks for your reply

I have tried that and there is no change in the error :(

as far as Stephany idea of using load load is not a member of PictureBox
maybe that may throw some more light on the problem

Roger
 
You're right. The PictureBox.Load method is not exposed in the Compact
Framwork.

I emphasise again that it is nothing to worry about unless it is causing an
unhandled exception to be thrown. If it is then handle it.

The 'first chance' messages only appear when you are in 'debug' and then (as
far as I am aware) only if you are running in the IDE.
 
Ok thanks for all the help and assistance

its just very annoying and just for information when I run the application
on the device the firts chance messages still appear.
and it does slow the device.
When I run standalone then you are correct the device runs at normal speed.

Once again thanks for the help

I will continue to watch this group as it appears to be well used and very
helpful

Good luck to all and Happy New Year

Roger
 
When it comes to the Compact Framework there is actually a dedicated
newsgroup:

microsoft.public.dotnet.framework.compactframework

You might get better help there for questions relating to the Compact
Framework.
 
I can't look up the docs (or test) on the compact framework but you might
check the data type of the Image property on the PictureBox just to make
sure. Take the picture box out of the equation (for testing purposes) and
simply try to cast the Bitmap into an Image (if that is the right datatype).
I've been using .PNG graphics but there is no reason that .JPG shouldn't
work the same.
 
Back
Top