A generic error occurred in GDI+http://forums.asp.net/t/624305.aspx/1?A+generic+error+occurred+in+GDI+Thu, 15 Sep 2011 06:12:12 -0400624305624305http://forums.asp.net/p/624305/624305.aspx/1?A+generic+error+occurred+in+GDI+A generic error occurred in GDI+ I received the foolowing message when attempting to upload a message. I do not have any .Net experience. Is there anyone out there that will take the time to give me a hand with this .Net error message? This appears to be a really nice looking and funtional image gallery and I would really enjoy using for family photos. Jimmy......................................................... A generic error occurred in GDI&#43;. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI&#43;. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: -------------------------------------------------------------------------------- [ExternalException (0x80004005): A generic error occurred in GDI&#43;.] System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams) &#43;582 nGallery.Lib.PhotoCache.GetScaledPicture() &#43;1747 nGallery.Lib.PhotoCache.GetThumbnail() &#43;66 nGallery.admin.addPicture.btnSubmit_ServerClick(Object sender, EventArgs e) &#43;651 System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) &#43;108 System.Web.UI.HtmlControls.HtmlInputButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) &#43;57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) &#43;18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) &#43;33 System.Web.UI.Page.ProcessRequestMain() &#43;1277 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 2004-07-04T21:50:54-04:00625611http://forums.asp.net/p/624305/625611.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ I've found more information regarding this error. It has seen some trouble in other applications. This knowledge base article describes the problem: <a href="http://support.microsoft.com/?id=814675">http://support.microsoft.com/?id=814675</a> Now the question is, what is the solution for nGallery? On a separate note, if this problem exists and is known for GDI&#43;, how come other users don't experience this problem? Is it really just a permissions issue and not related to the aforementioned KB Article? FYI, I experience this problem after a clean install of the gallery. The Check Permissions function returns all PASSED results. 2004-07-06T11:29:44-04:00625632http://forums.asp.net/p/624305/625632.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ Okay. So apparently it is just a regular permissions issue. <a href="http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&amp;PostID=577640"> This article</a> describes what one should do. Note, when one mentions the &quot;ASP Worker Process&quot;, this is the ASPNET account (at least for me). Giving this account full control access on the data, upload, and photo directories fixed the problem. 2004-07-06T11:45:52-04:00626078http://forums.asp.net/p/624305/626078.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ This error is a common one and also very tricky. The error itself is not very descriptive. Permission problems is the common cause, but there have been some cases where the permissions are fine and it still happens. I've seen some articles on this error, but the same error message is shown for completely different causes. We've seen it for permissions to the photos directory, permissions to the IIS temporary directory, and even more random stuff. The first link you posted is most likely not the cause. It is talking about errors when constructing the image and disposing the image, not when it is saving it. Also, at the buttom it says it applies to .NET 1.0, doesn't mention .NET 1.1. Glad you got the problem taken care of! Sorry for the slow response, wasn't around too much with the 4th of July weekend. 2004-07-06T17:35:36-04:002014493http://forums.asp.net/p/624305/2014493.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p><b><u>System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI&#43;. WHEN YOU TRY TO SAVE A BITMAP</u><br> </b></p> <p>you can not save the same Bitmap whihch you loaded into the object as it is bieng used by the other process at the same time....</p> <p>So first rename it and then try to save....</p> <p>&nbsp;<br> <br> </p> <pre class="prettyprint">//Step 6 : Try to save the image // this file is exclusively locked by BITMAP process so PERHAPS error may occur so first prefix the s_ before image //Now save this image ObjBitmap.Save(TargetPath &#43; &quot;s_&quot; &#43; tmpFileName, System.Drawing.Imaging.ImageFormat.Jpeg); //STEP 7 : CLEAN UP //Destroy the Graphics Object ObjGraphics.Dispose();</pre><pre class="prettyprint"> <span class="cmt">//DESTROY thE Bitmap Object and UNLOCK the file</span> ObjBitmap.Dispose();</pre><pre class="prettyprint"> <span class="cmt">//Delete the Temporarily Uploaded image</span> File.Delete(TargetPath + tmpFileName); lblMessage.Text = <span class="st">"Stamping Done"</span>;</pre><pre class="prettyprint">&nbsp;</pre><pre class="prettyprint"><b>I hope this will be help full for you.... If you find this info helpfull please do not forget to mark it as answer</b></pre>&nbsp;<br> &nbsp; 2007-11-19T13:42:28-05:002328953http://forums.asp.net/p/624305/2328953.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p>&nbsp;If this error is caused by permissions then there are two possible scenarios:</p> <ul> <li>The account the process is running as does not have permission to write to the target directory. Fix your permissions.</li><li>The target directory does not exist. Create it first.&nbsp;</li></ul> 2008-04-30T03:37:32-04:002866428http://forums.asp.net/p/624305/2866428.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p>Hi there,</p> <p>i did all solution but never solve this problem.</p> <p>i gave full permission folder and dispose() all bitmap and grabhics. its nothing.</p> <p><strong>But i try this one : <font color="#2b91af" size="2"><font color="#2b91af" size="2">GC</font></font></strong><font size="2"><strong>.Collect();&nbsp; and its working.</strong>&nbsp;i think iis working process cannot permission&nbsp;overwrite same&nbsp;bitmap. Because of bitmaps lifetime.</font></p> <p>So i use Garbace Collector and solve this problem. My code is working fine.</p> <p>Regards,</p> <p><font size="2">&nbsp;</p> </font> 2009-01-14T09:18:14-05:002906917http://forums.asp.net/p/624305/2906917.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p>thanks man that worked</p> 2009-02-01T09:46:47-05:003398486http://forums.asp.net/p/624305/3398486.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p>Yea, just needed to do a .Dispose(); when done with the first System.Drawing.Image<br> </p> 2009-09-10T20:46:42-04:003449202http://forums.asp.net/p/624305/3449202.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p>I know its very old post. I am just posting due to the reason if some one will search this error &amp; ma get solution.</p> <p><br> </p> <p>I was also facing same error, i did lots of R&amp;D. Actually i was saving files in a temporary folder after uploading. After that i was performing some operations on the image and saving resultant image in a different folder and deleting file in temporary folder. </p> <p>Actually temporary folder is empty, after publishing , that temporary folder does not exist in published project. so, for saving file temporarily, it is not getting path.</p> <p>then i have manually created empty temporary folder in published folder.</p> <p>its working f9 now. <br> </p> 2009-10-09T05:28:24-04:003510446http://forums.asp.net/p/624305/3510446.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p></p> <blockquote><span class="icon-blockquote"></span> <h4>MinaSamy</h4> <p></p> <p>thanks man that worked</p> <p></p> </blockquote> <p></p> <p><br> </p> <p>Of course that worked! Thanks for advice :)<br> </p> 2009-11-13T06:59:39-05:003699694http://forums.asp.net/p/624305/3699694.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p><a href="/members/dacraka.aspx">@dacraka</a> Completly Agree with you,one need to dispose the objects insted of carry them further... have a look a</p> <p><br> </p> <p>private void SaveAsThumbNail(int thumb_height, int thumb_width, FileUpload FileUpldCntrl, string imgPath)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Drawing.Image myimage;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileUpldCntrl.SaveAs(Server.MapPath(imgPath));<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myimage = System.Drawing.Image.FromFile(Server.MapPath(imgPath));<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Drawing.Bitmap source_bitmap = new System.Drawing.Bitmap(myimage);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myimage.Dispose();<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Drawing.Bitmap thumb_bitmap = new System.Drawing.Bitmap(thumb_width, thumb_height);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(thumb_bitmap);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.FillRectangle(System.Drawing.Brushes.White, 0, 0, thumb_width, thumb_height);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.DrawImage(source_bitmap, 0, 0, thumb_width, thumb_height);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g.Dispose();<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Drawing.Imaging.ImageCodecInfo[] Info = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Drawing.Imaging.EncoderParameters Params = new System.Drawing.Imaging.EncoderParameters(1);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Params.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; thumb_bitmap.Save(Server.MapPath(imgPath), Info[1], Params);<br> <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (Exception ex)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CommonFunctions objcom = new CommonFunctions();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objcom.LogError(Convert.ToString(Page.Page), Convert.ToString(ex.TargetSite.Name),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.Message.ToString(), HttpContext.Current, ex); <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> </p> 2010-02-25T05:56:45-05:003860258http://forums.asp.net/p/624305/3860258.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p>This is only for read and write permision. Just enable write permision on your folder.</p> <p>hopeful it will solve your problem.<br> </p> 2010-05-22T18:40:21-04:003963066http://forums.asp.net/p/624305/3963066.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p>Hello Friends,</p> <p>as me was blocked on the same issue from last 3-4 days n tried a lot of different attempts for the same but not a single one turned out to be successful.<br> But finally today i got the solution.</p> <p><b>After making it double sure that all the permissions are set to WRITE.</b></p> <p><br> USE string filepath = Server.MapPath(&quot;./Images/&quot;);<br> instead of <br> string filepath = Server.MapPath(&quot;~//Images//&quot;);<br> <br> the main issue was while mapping a virtual path<br> it starts the path from site folder<br> so&nbsp; we need to map with &quot;<b>.</b>&quot; instead of &quot;<b>~</b>&quot;<br> <br> I have tried the same solution on 3 different projects for the same problem.<br> all of them started working very smoothly.<br> All the best.....&nbsp; :)</p> 2010-07-08T10:09:47-04:004598045http://forums.asp.net/p/624305/4598045.aspx/1?Re+A+generic+error+occurred+in+GDI+Re: A generic error occurred in GDI+ <p>Hi,</p> <p>If you are getting that error , then I can say that your application doesn't have a write permission on some directory [where your trying to save or write image].</p> <p>For example, if you are trying to save the Image from the memory stream to the file system , you may get that error.</p> <p>I also faced that error when I was using Infragistics charts control , the control was trying to create a temporary chart in ChartImages folder and my application was not given the write permission.</p> <p>Please if you are using XP, make sure to add write permission for the aspnet account on that folder.</p> <p>If you are using windows server (2003,2008) or Vista, make sure that add write permission for the Network service account.</p> <p>Hope it help some one.</p> <p></p> 2011-09-15T06:12:12-04:00