[Mono-dev] Error in Mono but not on IIS: A null reference or invalid value was found [GDI+ status: InvalidParameter]

Matthew Urbano matthew.urbano at trailerpark.com
Mon Oct 18 15:03:55 EDT 2010

Hello Mono world!  I am having a difficult time trying to figure out a way to create an image cropping tool using c# and JQuery's Jcrop plug-in.  I can get the code to work perfectly in plain old .net, but mono gives me the following error:

A null reference or invalid value was found [GDI+ status: InvalidParameter]

Description: HTTP 500. Error processing request.

Stack Trace:

System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0
  at System.Drawing.Bitmap.SetResolution (Single xDpi, Single yDpi) [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.Drawing.Bitmap:SetResolution (single,single)
  at Fankit.ProfilePictures.btnCrop_Click (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0
  at System.Web.UI.WebControls.Button.OnClick (System.EventArgs e) [0x00000] in <filename unknown>:0
  at System.Web.UI.WebControls.Button.RaisePostBackEvent (System.String eventArgument) [0x00000] in <filename unknown>:0
  at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent (System.String eventArgument) [0x00000] in <filename unknown>:0
  at System.Web.UI.Page.RaisePostBackEvent (IPostBackEventHandler sourceControl, System.String eventArgument) [0x00000] in <filename unknown>:0
  at System.Web.UI.Page.RaisePostBackEvents () [0x00000] in <filename unknown>:0
  at System.Web.UI.Page.ProcessRaiseEvents () [0x00000] in <filename unknown>:0
  at System.Web.UI.Page.InternalProcessRequest () [0x00000] in <filename unknown>:0
  at System.Web.UI.Page.ProcessRequest (System.Web.HttpContext context) [0x00000] in <filename unknown>:0

Here is the code behind:

protected void btnCrop_Click(object sender, EventArgs e)
            string ImageName = CurrentImage.Value;
            string ImageNameOnly = CurrentImage.Value.Substring(CurrentImage.Value.LastIndexOf("/") + 1, CurrentImage.Value.Length - CurrentImage.Value.LastIndexOf("/") - 1);
            int w = Convert.ToInt32(W.Value);
            int h = Convert.ToInt32(H.Value);
            int x = Convert.ToInt32(X.Value);
            int y = Convert.ToInt32(Y.Value);

            string originalFile = Server.MapPath("~/cms/uploads/" + ImageNameOnly);

            using (var photo = System.Drawing.Image.FromFile(Server.MapPath("~/cms/uploads/" + ImageNameOnly)))

            using (var result = new Bitmap(w, h, photo.PixelFormat))
                result.SetResolution(photo.HorizontalResolution, photo.VerticalResolution);

                using (var g = Graphics.FromImage(result))
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    g.DrawImage(photo, new Rectangle(0, 0, 100, 100),
                         new Rectangle(x, y, w, h),


                    //result.Save(sp + "crop-" + ImageNameOnly);
                    imgCropped.ImageUrl = "/cms/uploads/crop-" + ImageNameOnly;



It seems like this line is the root of the problem: using (var photo = System.Drawing.Image.FromFile(Server.MapPath("~/cms/uploads/" + ImageNameOnly)))

Is there a way around this error??

Matthew Urbano | Web Developer
Trailer Park Interactive
6922 Hollywood Blvd., 7th floor
Hollywood, CA  90028
T: 310-845-3021
M: 305-790-1805
matthew.urbano at trailerpark.com<mailto:matthew.urbano at trailerpark.com>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20101018/91a5535d/attachment.html 

More information about the Mono-devel-list mailing list