Forum Moderators: open

Message Too Old, No Replies

Using System.Drawing.Image.FromFile()

Object reference not set to an instance of an object.

         

garann

12:51 am on Mar 28, 2003 (gmt 0)

10+ Year Member



Hi,

I'm at my wit's end trying to figure out why these little snippets of code won't work:


Dim baseImg As bitmap = bitmap.fromfile(request.physicalApplicationPath & "\tempImgs\temp." & ext)

or


Dim baseImg As bitmap = new bitmap(request.physicalApplicationPath & "\tempImgs\temp." & ext)

or


Dim baseImg As new bitmap(request.physicalApplicationPath & "\tempImgs\temp." & ext)

I'm just trying to create a new Bitmap (a System.Drawing.Image would work, too) from a file. Each time I try, I get a NullReferenceException:


[NullReferenceException: Object reference not set to an instance of an object.]
System.Drawing.SafeNativeMethods.GdipCreateBitmapFromStream(IStream stream, IntPtr& bitmap) +0
System.Drawing.Bitmap..ctor(Stream stream) +117
ASP.throwaway2_aspx.Page_Load(Object obj, EventArgs E) in D:\htdocs\tech-secstate-wa-gov\generalwebtools\throwaway2.aspx:22
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724

Things I've already checked:
- Using a Stream instead of a File as my argument to the constructor
- That the argument I'm giving it isn't null
- Running this from a VB class, instead of ASP, where it is now
- Giving this ASP app every conceivable permission on the server

Can anyone help?
Thanks a ton,
g.

Xoc

12:38 am on Mar 29, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I did a brief test. The basic syntax of the line is okay. So:

1) Either request.physicalApplicationPath isn't resolving to what you expect.
2) Your filename doesn't exist.
3) Your file is corrupt.
4) ext doesn't resolve to what you expect.

garann

4:19 pm on Mar 31, 2003 (gmt 0)

10+ Year Member



Hi Xoc,

There's nothing wrong with the filename I'm giving it. I save the file to that location using the same code on the line above this one, and the files show up fine. When I print it to the screen, it's exactly what I'd expect it to be. I get the same error trying to create Images and Bitmaps with their dimensions, instead of loading a file.

Thanks for trying,
g.