Loading enbedded image...

L

Len Weaver

Hello all,

I have some fairly simple code that keeps throwing an exception.
The exception message is "A generic error occurred in GDI+.". Okay, I
know what you're thinking. You're thinking: "But Len, that error
message is soooo descriptive how could you possibly not know what the
problem is?".

There are many examples of this problem listed on Google groups, but
they either involve ASP.Net applications, or saving an image to disk.
None of the solutions listed seem to apply to my situation. Here is
some sample code that replicates my problem:

public Bitmap MenuImage {
get {
Bitmap result = null;
Stream s = null;

try {
s = this.GetType().Assembly.GetManifestResourceStream
("MyNamespace.Graphics.SECUR07.ICO");

result = (Bitmap)Image.FromStream( s );
}
catch( Exception Ex ) {
throw new ApplicationException( "Unable to retrieve Add-In "
+
"menu bitmap.", Ex );
}
finally {
if( s != null ) s.Close();
}

return result;
}
}

private void pictureBox1_Click(object sender, System.EventArgs e) {

pictureBox1.Image = ((IMenuImage)this).MenuImage; //Exception
thrown here
}

The 'Build Action' for "SECUR07.ICO" is set to 'Embedded Resource'.
Any assistance would be appreciated.

Thanks,
Len
 
G

Guest

Have you tried putting a MessageBox.Show(ex.ToString()); in your catch
statement?

This will usually give more specific information in the few rare cases where
it gives you the generic error message
 
C

Christopher Walls

I ran into this in my ASP.NET application that accepted image files via file
upload and then resized them. I actually got this silly message for two
different errors. One was security - the account ASP.NET was running under
did not have create permissions in the directory where I was creating my
thumbnail. The other was I had a file name misspelled which resulted in the
file not being found.

Hope this helps.

- Chris
 

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