Loading enbedded image...

  • Thread starter Thread starter Len Weaver
  • Start date Start date
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
 
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
 
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
 
Back
Top