Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an windows application which loads many images.recently i have been getting the below exception. I have checked my code am not using ICON anywhere also i am unable to recreate the error evertime it happens only after the application has run for atleast half hour or so. Can any body help?
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
   at System.Drawing.Icon.ToBitmap()
   at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
   at System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
   at System.Windows.Forms.Control.WndProcException(Exception e)
   at System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at IZZone.Program.Main()
Posted
Updated 28-Jan-11 6:04am
v2
Comments
Sergey Alexandrovich Kryukov 28-Jan-11 11:44am    
You can also dump exception more detailed exception info: include exception stack, it will show line numbers and also all inner exceptions -- recursively. Dump it in some text file, then present sufficient code sample and indicate in which line(s) exception was raised/handled. Post both dump and code.

So far, you did not even report exception Message (what you show does not include Message).
How can you hope someone point out your problem without this data?
See System.Exception for more detail.

--SA
William Winner 28-Jan-11 12:10pm    
What is calling the constructor? what code are you using? Without that, we really can't help.
Nish Nishant 28-Jan-11 12:29pm    
That is not fired from his code. That much is evident from the call stack.
Apex_Va 31-Jan-11 0:24am    
Even i wanted the exact line number where of the exception so I placed try/catch blocks through out my code but somehow the exception is only caught in the main program.cs. Strangely i am unable to reproduce the error on my machine its happening only in production. I even included the/pdb(debug symbols) file in production build to get the line number but no luck. As nishant suggested i am trying to check if the code is disposing all the image objects properly but so far i dont find any problem there. Is there any way i can get the line number
Apex_Va 3-Feb-11 0:29am    
i finally got line number the error is thrown when i am trying to open a form
FromToSPG fromToSpg = new FromToSPG(FromToSPG.FromToSPGMode.StartClip, articleMetaData, allkeywords, e.Zone, pageCollection, false, toolOptions.BatchNumber, null);
if (fromToSpg.ShowDialog() == DialogResult.OK)
{//do something
}
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) at System.Drawing.Bitmap..ctor(Int32 width, Int32 height) at System.Drawing.Icon.ToBitmap() at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t) at System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t) at System.Windows.Forms.Control.WndProcException(Exception e) at System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()

Most likely cause is that either width or height is negative.

[Update]

Okay, having read your update it seems to me that you are not releasing unused GDI handles. The error you get is kinda arbitrary (and not from your user code). I believe that when Windows tries to repaint the app icon, coincidentally it hits the GDI handle limit, which results in some failed GDI calls, so by the time Icon.ToBitmap calls the Bitmap ctor, many or all the arguments are invalid (you cannot see this unless you have the public symbols for debugging).

So your next step is to double check if you are properly disposing off all your image objects after they are done with.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 28-Jan-11 11:48am    
Maybe you're right. Why doing guesswork, let's demand good exception report.
--SA
Sandeep Mewara 28-Jan-11 12:04pm    
Comment from OP:
Thanks Nishant but i checked the code and whenever i am trying to load a bitmap i make sure the co-ordinates are within the bounds.Also i tried to load a bitmap giving negative width/height but the error i get dosent have System.Drawing.Icon.ToBitmap line in the exception message
This[^] thread may provide a solution to you.
 
Share this answer
 

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



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