Quantcast
Channel: .Net Core | MVC | HTML Agility Pack | SQL | Technology Crowds
Viewing all articles
Browse latest Browse all 544

Fix GDI: A generic error occurred in GDI in MVC Application

$
0
0

Introduction

Providing solution to very common issue "A generic error occurred in GDI+." while working with ASP.Net MVC C# application. In this application, I was writing code to save image in Png format. Sometimes, we don't have any exact idea about issue, then we can wastage our precious development time, to overcome this issue, I come up here with to resolve this issue.  

Problem Where Encountered

img1.Save(Server.MapPath("/Upload/test.png", System.Drawing.Imaging.ImageFormat.Png);

Few other more reasons to arise issue A generic error occurred in GDI+

  1. This error can also comes out while upload folder don't have permissions to save image.
  2. If we are creating image from bytes and bytes are locked then this also throws relevant exception.
  3. Check for the same file/image exists in the same folder.
  4. Always use dispose method to deallocate memory while image/file generating from bytes array.
    A generic error occurred in GDI
    Fig: A generic error occurred in GDI

Conclusion

I was saving png image under Upload folder, unfortunately Upload folder was not available in MVC app location, so I needed to create a new Upload folder to upload png image to that specific folder, this is the way, how we can remove error A generic error occurred in GDI.

Suggested Reading


Viewing all articles
Browse latest Browse all 544

Trending Articles