locked
Parameter is not valid at System.Drawing.Bitmap..ctor( RRS feed

  • Question

  • 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()

    Monday, January 31, 2011 5:27 AM

Answers

  • Hi Bob

    I dont set any icon for my forms its default windows icon. I could finally get the line number where the error is thrown it happens when i try to open a winform but the strange thing is it doesnt happen at my end only when the production runs it for sometime we get this error.

    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()

    Code the error is thrown is

    FromToSPG fromToSpg = new FromToSPG(FromToSPG.FromToSPGMode.StartClip, articleMetaData, allkeywords, e.Zone, pageCollection, false, toolOptions.BatchNumber, null);

     if (fromToSpg.ShowDialog() == DialogResult.OK) {//do something }

    The application opens many forms and i noticed that we are not diposing these form objects. 

     

     

    • Proposed as answer by Jie Bao Monday, February 7, 2011 4:35 PM
    • Marked as answer by Jie Bao Tuesday, February 8, 2011 10:19 AM
    Friday, February 4, 2011 6:23 PM
  • Than that's the probable root of the problem. Dispose them!  Or try calling GC.Collect() from time to time.
    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    • Proposed as answer by Jie Bao Monday, February 7, 2011 4:35 PM
    • Marked as answer by Jie Bao Tuesday, February 8, 2011 10:19 AM
    Friday, February 4, 2011 9:04 PM

All replies

  • Do you have any idea on which line of code this exception getting generated throwing. If yes then post that piece of code over here.

    If no, then we need to find the place from which the exception is getting generated. For that add logging statement on entry and exit of each method. Once the exception is generated, check the log file to find out from where.

     


    Thanks,
    A.m.a.L
    [MVP Visual C#]
    Dot Net Goodies
    Don't hate the hacker, hate the code
    Monday, January 31, 2011 5:35 AM
  • Anyupdate?

    How do you set the properties of your project? Do you set the ICON for the applciation or the form?

    Agree with A.m.a.L, could you please share some code snippet about the exception, such as the code which throws it?

    Why it will create a ThreadExceptionDialog to show the exception? What is the version of your .Net?

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 3, 2011 9:38 AM
  • Hi Bob

    I dont set any icon for my forms its default windows icon. I could finally get the line number where the error is thrown it happens when i try to open a winform but the strange thing is it doesnt happen at my end only when the production runs it for sometime we get this error.

    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()

    Code the error is thrown is

    FromToSPG fromToSpg = new FromToSPG(FromToSPG.FromToSPGMode.StartClip, articleMetaData, allkeywords, e.Zone, pageCollection, false, toolOptions.BatchNumber, null);

     if (fromToSpg.ShowDialog() == DialogResult.OK) {//do something }

    The application opens many forms and i noticed that we are not diposing these form objects. 

     

     

    • Proposed as answer by Jie Bao Monday, February 7, 2011 4:35 PM
    • Marked as answer by Jie Bao Tuesday, February 8, 2011 10:19 AM
    Friday, February 4, 2011 6:23 PM
  • Than that's the probable root of the problem. Dispose them!  Or try calling GC.Collect() from time to time.
    "To alcohol! The cause of and solution to all of life's problems." - Homer Simpson
    • Proposed as answer by Jie Bao Monday, February 7, 2011 4:35 PM
    • Marked as answer by Jie Bao Tuesday, February 8, 2011 10:19 AM
    Friday, February 4, 2011 9:04 PM