System.ArgumentNullException

T

Tom C

This error occurs erratically at startup. It appears to be all native
code. Does anyone have any idea what the heck could be cauing this?

System.ArgumentNullException: Value cannot be null.
Parameter name: pen
at System.Drawing.Graphics.DrawLine(Pen pen, Int32 x1, Int32 y1,
Int32 x2, Int32 y2)
at dh.OnPaint(PaintEventArgs e)
at
System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.OnPrint(PaintEventArgs e)
at System.Windows.Forms.Control.WmPrintClient(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at dh.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)
 
B

Brian Gideon

This error occurs erratically at startup. It appears to be all native
code. Does anyone have any idea what the heck could be cauing this?

System.ArgumentNullException: Value cannot be null.
Parameter name: pen
   at System.Drawing.Graphics.DrawLine(Pen pen, Int32 x1, Int32 y1,
Int32 x2, Int32 y2)
   at dh.OnPaint(PaintEventArgs e)
   at
System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.OnPrint(PaintEventArgs e)
   at System.Windows.Forms.Control.WmPrintClient(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at dh.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)

I have seen an ArgumentNullException generated inside the control
painting routines when threading is used incorrectly with windows
applications. What happens is another thread modifies a control which
causes it to enter a half-baked state the moment it simultantenously
receives say the WM_PAINT message. Remember, only the UI thread can
ever access a windows control or form. I'm not saying that's what's
happening here, but it is one thing to consider.
 
T

Tom C

I have seen an ArgumentNullException generated inside the control
painting routines when threading is used incorrectly with windows
applications.  What happens is another thread modifies a control which
causes it to enter a half-baked state the moment it simultantenously
receives say the WM_PAINT message.  Remember, only the UI thread can
ever access a windows control or form.  I'm not saying that's what's
happening here, but it is one thing to consider.- Hide quoted text -

- Show quoted text -

Thanks for the input Brian. We really use threads rather sparingly so
we took a look and really don't SEE anything readily obvious. Does
anyone have any ides on how we might be able to capture more
information about the error when it occurs as we seem to be at a
disadvantage as it appears to all be native code.
 
C

Chris Dunaway

Thanks for the input Brian. We really use threads rather sparingly so
we took a look and really don't SEE anything readily obvious. Does
anyone have any ides on how we might be able to capture more
information about the error when it occurs as we seem to be at a
disadvantage as it appears to all be native code.

Shot in the dark:

You're not using one of the pre-defined pens in the Pens class and
then disposing of it are you?

Chris
 
B

Brian Gideon

The stack reads from bottom to top, so the last thing to happen was your
dh.OnPaint(..) event handler called System.Drawing.Graphics.Draw with a null
pen. The rest of the stack is just how the paint message got to your event
handler.

I am assuming that dh.OnPaint(..) is a handler you wrote, for a control you
named dh. So, maybe try putting a check of pen in front of the call to
Graphics.Draw. Generate some debug messages if something ain't right with it.

Another idea I had was to use Reflector to look at the system methods
that are called to see what scenarios may cause that pen parameter to
be null. That might give the OP some more clues anyway.
 

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