0

I am trying to put a picture in a picturebox, but I keep getting an ArgumentException that says "Value of 'null' is not valid for 'stream'." I don't know what I'm doing wrong.

Stream myStream = myAssembly.GetManifestResourceStream("WindowsFormsApplication2.Resources.clock3.png");

Image img = Image.FromStream(myStream);
pictureBox1.Image = img;
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Sarah
  • 133
  • 1
  • 3
  • 13
  • I presume the exception is actually thrown on `Image.FromStream` rather than `pictureBox1.Image = img`, right? – p.s.w.g Dec 08 '13 at 21:29
  • @p.s.w.g yes you are right. – Sarah Dec 08 '13 at 21:30
  • 2
    In that case I guess the resource name is wrong, because `myStream` is actually null. See http://stackoverflow.com/questions/10726857/why-does-getmanifestresourcestream-returns-null-while-the-resource-name-exists-w – p.s.w.g Dec 08 '13 at 21:31
  • does your image is contained in application.resources – BRAHIM Kamel Dec 08 '13 at 21:34
  • @p.s.w.g but i am sure that the resource name is correct – Sarah Dec 08 '13 at 21:35
  • 2
    @ELF You might try calling [`GetManifestResourceNames`](http://msdn.microsoft.com/en-us/library/system.reflection.assembly.getmanifestresourcenames(v=vs.110).aspx) just to verify. – p.s.w.g Dec 08 '13 at 21:37
  • @p.s.w.g it didn't work, thanks though. – Sarah Dec 08 '13 at 22:10

0 Answers0