NotSupportedException for PictureBox image in CF 2.0

S

Sacha Korell

I am developing a barcode scanner application using VSNET2005 for the WM 5.0
platform. When I associate an image with a PictureBox control at design
time, I get a "NotSupportedException" at runtime. I have tried gif and bmp
file format for the image. I do not get an error if I just have the
PictureBox control with no image associated.

The error message is as follows:
Error
ScannerApp.exe
NotSuportedException
System.Drawing.Bitmap

at System.Resources.ResourceReader.LoadObjectV2()


If need be I can post the whole stack trace, but it would have been a lot to
type ;-) So I hope the last line will give somebody a clue as to what the
problem might be.

Thanks,
Sacha
 
M

maxhamster

I had the same problem. And it drove me insane! On the compact
framework each method can only have 64k IL code (like byte code in
Java). Debugging adds just enough code to the resource designer code to
push it over that limit.

To get around this I instead embedded the image in the exe and accessed
it using the ManifestResourceStream. The only down side of this is that
you will not see the image in the designer. The code to do this is as
follows:
System.Reflection.Assembly _assembly =
System.Reflection.Assembly.GetExecutingAssembly();

picturebox1.Image = new System.Drawing.Bitmap(
_assembly.GetManifestResourceStream( "AppName.FolderName.ImageName"));

where AppName is the name of your project and FolderName is the name of
the folder you placed the image in.

Now for some reason for my app, if I got the executing assembly right
befor I got the image it would be "System.Paint" not my exictable. so i
had to cache the refrence to the assembly befor making the form.

I hope this fixes it!

Max Hamilton
 
S

Sacha Korell

That's strange. Then why would MS even provide a way to add an image to the
picture box control at design time?
I'll try your suggestion. Thanks!

Sacha
 
S

scullinan

We are seeing a very similar phonomena, but only on one particular
machine. On our other machine's everything works fine, but on our one
main dev machine we are seeing the unsupported error mentioned above.

We tried this workaround but we get a null reference exception when it
hits this line of code. Do you have a more detailed piece of sample
code you can send?

Alternatively, has anyone else seen this? It is very odd that it is
only happening on one machine. Other projects on this same machine
display pictureboxes fine which futher complicates things. We have
even tried recreating our project from scratch, adding the forms and
usercontrols back in manually and the problem persisted.

Any help would be greatly appreciated as we are in crunch time for this
project and have wasted 2 days fighting this issue.

Thanks,

Sean
 

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