Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am facing the following exception in my C#.net win forms application.
A generic error occurred in GDI+.
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawRectangle(Pen pen, Int32 x, Int32 y, Int32 width, Int32 height)
at WeifenLuo.WinFormsUI.Docking.DockWindow.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
The most confusing point is that, it occurs very rarely when the application loading a form (which contains some rich graphics, WPF work etc.), could say about 90% of the time the form is loaded successfully. but very few times it happens to be reproduced and also only on some machines, at some other machines this form is works 100% of the time and never face this exception.

I am not getting any idea why this exceptions happening, because it also not showing the exact stack trace which causes the exception. Please suggest if one have any idea about how to deal with it.
Posted
Updated 20-Feb-12 8:43am
v2
Comments
Sergey Alexandrovich Kryukov 20-Feb-12 10:00am    
WPF? No kidding?
--SA
Sergey Alexandrovich Kryukov 20-Feb-12 10:01am    
Short answer: you did something wrong. How can we tell you what exactly? Our access to your hard disk is limited. :-)
--SA

1 solution

I recently had that same exception. Actually the problem I had was that a program was trying to write a file to a folder that didn't exist. The file was a gif created from the application.
Now you wouldn't guess, but I created the folder and everything went fine. Who would think a Generic GDI+ Exception would really be IO related? :)
Anyway, after Googling a bit I found more people have this problem.
Solving "A Generic Error Occurred In GDI+" Exception[^]
Perhaps one of these search results[^] will help.
The problem with this Exception is that it tells you nothing (I actually think this is a code flaw or even bug in the framework) and you can't tell us anything as a result. So finding help is difficult.
Anyway, check if your code needs (write) access to some files or folders and make sure the file or folder exists and that you have permission to write.
Good luck with this vague Exception!
Hope it helps :)
 
Share this answer
 
Comments
Muhammad Idrees GS 21-Feb-12 1:12am    
Thanks Naerling,

Yes that's the problem I understand from your post. I checked in this perspective and test accordingly. now the form is working fine.

Thanks a lot again for helping me to get out from this fuzzy exception.
Sander Rossel 21-Feb-12 1:53am    
No problem, glad you got it sorted out :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900