Image error

  • Thread starter Thread starter yamne
  • Start date Start date
Y

yamne

When I do:

Image Pippo = new Bitmap(System.Reflection.Assembly.GetExecutingAssembly().

GetManifestResourceStream("MedicAlertClient.images." + imageName));


I have this error:

An unhandled exception of type 'System.NullReferenceException' occurred in
System.Drawing.dll

Why???

Thanks
Damiano
 
It could be:

(a) imageName is an empty string
(b) the image referenced by imageName is not in the assembly's manifest
(c) imageName is missing its file extension
(d) the namespace is incorrect

HTH
Neil
 
Try :
string imgPath =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssem
bly().GetName().CodeBase);
this.pictureBox1.Image = new Bitmap(imgPath + @"\imageName.jpg");
 
On top of what Neil said...
I get a feeling that you *might be* embedding the images in an assembly
other than primary (a DLL), in which case you need to be careful with where
the GetExecutingAssembly is called from.
To troubleshoot this kind of problem I find it useful to enumerate the
actual resource names using :

foreach( string s in
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()
)
{
MessageBox.Show(s, "");
}
 
How I can resolve the problem ???

damiano

Alex Feinman said:
On top of what Neil said...
I get a feeling that you *might be* embedding the images in an assembly
other than primary (a DLL), in which case you need to be careful with where
the GetExecutingAssembly is called from.
To troubleshoot this kind of problem I find it useful to enumerate the
actual resource names using :

foreach( string s in
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()
)
{
MessageBox.Show(s, "");
}
 
Well, where are your images? This is the point where you will need to show
some code
 
Back
Top