Image error

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
 
N

Neil Cowburn [MVP]

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
 
V

vish

Try :
string imgPath =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssem
bly().GetName().CodeBase);
this.pictureBox1.Image = new Bitmap(imgPath + @"\imageName.jpg");
 
A

Alex Feinman [MVP]

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, "");
}
 
Y

yamne

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, "");
}
 
A

Alex Feinman [MVP]

Well, where are your images? This is the point where you will need to show
some code
 

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