A generic error occurred in GDI+

∥☆過路亽.° 提交于 2019-11-29 06:18:22

I hate that error with a passion. Generic Error is possibly the most useless error description ever written.

When I've encountered it the problem as always been related to file IO.

Here is the list of fixes I keep in my notes- Not sure if these apply but they usually do the trick for me.

  • Check File path
    • Make sure that the parent directory exists
    • Ensure that path includes both the filename and extension
    • Use server.MapPath() to create the path
  • Make sure that the file isn't being written back to it's source. Close and reopen the stream if necessary.

My apologies if i stole this list from somewhere else. It has been in my notebook for awhile and I can't remember where it came from.

Everyone here (and on this site) has discussed this as due to a permissions error. I've stumbled over another flavor: memory. I ran out of memory and started receiving this error as well. So keep that in mind as another potential source of error.

In my particular case I was running in a .NET application, and running against a number of threads (few enough that I wasn't being held back too much by the GDI+ process-wide lock). Adding a "GC.Collect()" after major tasks finished didn't seem to affect the speed much, but did completely get rid of the out of memory errors.

I just had an similar problem (same exception) on my hosted website: It turned out to be a permissions issue, the ASP.NET account was trying to read image files from a directory outside its available scope.

I suggest you double-check the permissions as well as the <trust> element in web.config, it should be set to "Medium" or higher depending on where the files are located.

This one followed me for a long time. Yes you can check permissions but what you also should do is to dispose of your bitmap correctly.

bitmap.Dispose();

i agree permissions is the problem here.

network service maybe ?

I've got the same error just now and Google help me to find answer: Loading/Saving bitmap causes the locked file.

Workaround is create othe bitmap, save and let it release:

Bitmap tmp = new Bitmap(bitmapToBeSaved); tmp.SaveToFile(fileName);

Is your local machine Vista or Windows 7, and your server Windows Server 2003? I believe the GDI+ implementation differs, and you won't see the error on the newer OSs. I'm just running into this issue now, and that's one of the factoids I've come across.

Make sure IIS_WPG has the correct permissions on your upload folder and also ASPNET.

I just had the same problem and this fixed it.

Don't forget to propagate the permissions through your sub folders if required too ( I may have forgotten that.. :) )

sam

Do not use direct path

    System.Drawing.Image img = Base64ToImage(_ImagePath);
    img.Save(_attachmentPath, ImageFormat.Jpeg);

Use Server.MapPath and it will create Directory If needed

    System.Drawing.Image img = Base64ToImage(_ImagePath);
    img.Save(Server.MapPath(_attachmentPath), ImageFormat.Jpeg);

Please be sure about the path you are using for images,I also face the same error.Check all paths you are using.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!