Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows Forms
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 28-Jan-11 6:34am
Apex_Va328
Edited 28-Jan-11 7:04am
v2
Comments
SAKryukov at 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 at 28-Jan-11 12:10pm
   
What is calling the constructor? what code are you using? Without that, we really can't help.
Nishant Sivakumar at 28-Jan-11 12:29pm
   
That is not fired from his code. That much is evident from the call stack.
Apex_Va at 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 at 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()
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
v2
Comments
SAKryukov at 28-Jan-11 11:48am
   
Maybe you're right. Why doing guesswork, let's demand good exception report.
--SA
Sandeep Mewara at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

This[^] thread may provide a solution to you.
  Permalink  

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

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 Maciej Los 270
3 DamithSL 225
4 Afzaal Ahmad Zeeshan 202
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 28 Jan 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100