ToBitmap - Invalid Parameter Used

M

Marc Nemegeer

Hi,

I have a misterious problem, which I'm unable to solve. Can somebody give me
some clues where to start looking ??

We have an MDI application with child forms on it. Each of these forms has
an icon in the upper left corner :) From time to time, we get at random
time intervals, when the user clicks somewhere on the form an "Invalid
Parameter used".

The following is a stack dump :
ExceptionManager.InnerException1: Invalid parameter used.
ExceptionManager.Stack: 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.ThreadExceptionDialog..ctor(Exception t)
at System.Windows.Forms.ThreadContext.OnThreadException(Exception t)
at System.Windows.Forms.Control.WndProcException(Exception e)
at System.Windows.Forms.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.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at GeneralUI.Desktop.SingleInstance.Run(Form frmMain) in
D:\Ihc\GeneralUI\Desktop\SingleInstance.vb:line 38
at GeneralUI.Desktop.MainForm.Main() in
D:\Ihc\GeneralUI\Desktop\Mainform.vb:line 513

Any clues ? Or ideas ? Or is it something internal in the framework ? A
possible work around ??

Thanks,
Marc
 
M

Marcos Stefanakopolus

I saw a similar stack dump just yesterday. It turned out that a Bitmap
object that I thought contained a valid Bitmap was actually uninitialized.
I would bet that your situation is similar. In my case, I was being an
idiot: I had a method parameter called "result" that had the same name as a
field of "this" that I was trying to assign to, so naturally, I wasn't
getting what I thought I was getting.

In your case, make sure that the actual Icon resource being used contains an
icon of the correct size and depth for the parameters you're using. In the
past, I've had some horrible woes over icons because my .ico file didn't
have all the proper icon versions in it (such as 32x32 @ 256 colors, 16x16 @
16, etc), and the Visual Studio help was sorely lacking in information about
what WinForms expects your .ico files to have in them.

If you're using Visual Studio, put a breakpoint right before the line that
throws the exception (or maybe at the line, depending on your exact code),
and make sure that the result of the System.Drawing.Icon.ToBitmap() call is
a valid bitmap. If it's not, then load up your .ico file in the resource
editor, and right-click to get the context menu where you can see what
versions are in the file (and add new ones).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top