This generic exception is the worst exception that one can get while working with graphics objects. It just simply doesn't provide anything at all.
Quote:
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll Additional information: A generic error occurred in GDI+.
Even if you tried to get the
ErrorCode
it won't provide anything at all. Secondly, the main thing to understand is that once you load the graphics (bitmap), a lock is put on that file which doesn't allow updating or altering the file. This
solution of Hans Passant[
^] gives a good overview of using the using block to ensure that the previous bitmaps are properly disposed; you can write a
try...catch
alternative of that C# program to perform this in your C++ application.
For more,
ExternalException Class (System.Runtime.InteropServices)[
^]