NullReferenceException?

I receive this exception when i run my application:

******** Begin Exception ********
"System.NullReferenceException: Object reference not set
to an instance of an object.
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 CO.Win.MainModule.Main() in
C:\CODev\Utveckling\CO\CO.Win\Main.vb:line 128"
******** End Exception ********

It's impossible to find out where in my code its been
fired. I've got try-catch statements everywhere but the
exception appears only in my main module:

try
.
.
Application.Run(startForm)
Catch ex As System.NullReferenceException
End try

There is a datagrid on my form.

Thanks in advanced!

Re: NullReferenceException by Dmitriy

Dmitriy
Thu Aug 21 01:32:19 CDT 2003

Hi,

Is your data grid somehow customized? I have seen similar errors when custom
column styles were used and these column styles contained bugs.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software

"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
news:0f6201c3671f$05423ce0$a101280a@phx.gbl...
> NullReferenceException?
>
> I receive this exception when i run my application:
>
> ******** Begin Exception ********
> "System.NullReferenceException: Object reference not set
> to an instance of an object.
> 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 CO.Win.MainModule.Main() in
> C:\CODev\Utveckling\CO\CO.Win\Main.vb:line 128"
> ******** End Exception ********
>
> It's impossible to find out where in my code its been
> fired. I've got try-catch statements everywhere but the
> exception appears only in my main module:
>
> try
> .
> .
> Application.Run(startForm)
> Catch ex As System.NullReferenceException
> End try
>
> There is a datagrid on my form.
>
> Thanks in advanced!
>


Re: NullReferenceException by Mats-Erik

Mats-Erik
Thu Aug 21 02:01:25 CDT 2003

Yes i customize my datagrid with custom column styles. Are
there some ways to debug these exceptions? Do Microsoft
have guidlines/recommendations how to design custom column
styles?

Thanks!


>-----Original Message-----
>Hi,
>
>Is your data grid somehow customized? I have seen similar
errors when custom
>column styles were used and these column styles contained
bugs.
>
>--
>Dmitriy Lapshin [C# / .NET MVP]
>X-Unity Unit Testing and Integration Environment
>http://x-unity.miik.com.ua
>Deliver reliable .NET software
>
>"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
>news:0f6201c3671f$05423ce0$a101280a@phx.gbl...
>> NullReferenceException?
>>
>> I receive this exception when i run my application:
>>
>> ******** Begin Exception ********
>> "System.NullReferenceException: Object reference not set
>> to an instance of an object.
>> 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 CO.Win.MainModule.Main() in
>> C:\CODev\Utveckling\CO\CO.Win\Main.vb:line 128"
>> ******** End Exception ********
>>
>> It's impossible to find out where in my code its been
>> fired. I've got try-catch statements everywhere but the
>> exception appears only in my main module:
>>
>> try
>> .
>> .
>> Application.Run(startForm)
>> Catch ex As System.NullReferenceException
>> End try
>>
>> There is a datagrid on my form.
>>
>> Thanks in advanced!
>>
>
>.
>

Re: NullReferenceException by Mats-Erik

Mats-Erik
Thu Sep 04 04:31:06 CDT 2003

I've tried "Stop when an exeption occurs" but it doesnt
help.

The nullreferenceexception occurs before i even started
editing och clicking the datagrid.

The consequences of this exception is that this mission
ciritical application crasch.

What to do?

Thanks in advance!


>-----Original Message-----
>I have seen an article in MSDN outlining creation of a
custom column style,
>but as far as I remember it just covers the basics.
>
>As for the debugging, enable "Stop when an exception
occurs" mode in the
>debugger to see where exactly the exception is raised.
This might help and
>might not help as well if the exception occurs within the
DataGrid code.
>
>Besides of this, you should also ensure that:
>
>- If you override the TextBoxColumn's Commit method, DO
ENSURE that you call
>the base class implementation. Otherwise you'll have odd
exceptions raised
>when a cell is being edited.
>
>- Ensure that you do not pass unexpected values to base
class
>implementations
>
>Generally speaking, such an exception indicates that your
code does somthing
>that breaks the grid's internal state - and this is
caused mostly by lack of
>calling the base class implementation. Extreme care needs
to be taken with
>the Edit, Abort, Commit and ConcedeFocus methods as they
all participate in
>a complex sequence of the column lifecycle within the
grid.
>
>--
>Dmitriy Lapshin [C# / .NET MVP]
>X-Unity Unit Testing and Integration Environment
>http://x-unity.miik.com.ua
>Deliver reliable .NET software
>
>"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
>news:0ad401c367b2$097e0800$a101280a@phx.gbl...
>> Yes i customize my datagrid with custom column styles.
Are
>> there some ways to debug these exceptions? Do Microsoft
>> have guidlines/recommendations how to design custom
column
>> styles?
>>
>> Thanks!
>
>.
>

Re: NullReferenceException by Dmitriy

Dmitriy
Thu Sep 04 05:57:46 CDT 2003

1. Have you tried the rest of my suggestions?
2. Try to look at the stack trace after stopping program execution upon
NullReferenceException. This might help you figure out the approximate error
location - compare the method names in the stack trace with those you have
overridden, for example.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
news:197f01c372c7$446e8d20$a601280a@phx.gbl...
> I've tried "Stop when an exeption occurs" but it doesnt
> help.
>
> The nullreferenceexception occurs before i even started
> editing och clicking the datagrid.
>
> The consequences of this exception is that this mission
> ciritical application crasch.
>
> What to do?
>
> Thanks in advance!


Re: NullReferenceException by Mats-Erik

Mats-Erik
Thu Sep 04 07:35:11 CDT 2003

I've tried the rest bu with no results.

The stacktrace is:

******** Begin Exception ********
"System.NullReferenceException: Object reference not set
to an instance of an object.
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 CO.Win.MainModule.Main() in
C:\CODev\Utveckling\CO\CO.Win\Main.vb:line 128"
******** End Exception ********


>-----Original Message-----
>1. Have you tried the rest of my suggestions?
>2. Try to look at the stack trace after stopping program
execution upon
>NullReferenceException. This might help you figure out
the approximate error
>location - compare the method names in the stack trace
with those you have
>overridden, for example.
>
>--
>Dmitriy Lapshin [C# / .NET MVP]
>X-Unity Test Studio
>http://x-unity.miik.com.ua/teststudio.aspx
>Bring the power of unit testing to VS .NET IDE
>
>"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
>news:197f01c372c7$446e8d20$a601280a@phx.gbl...
>> I've tried "Stop when an exeption occurs" but it doesnt
>> help.
>>
>> The nullreferenceexception occurs before i even started
>> editing och clicking the datagrid.
>>
>> The consequences of this exception is that this mission
>> ciritical application crasch.
>>
>> What to do?
>>
>> Thanks in advance!
>
>.
>

Re: NullReferenceException by Dmitriy

Dmitriy
Thu Sep 04 08:31:23 CDT 2003

The stack trace eventually points to a Windows message handler. Do you
implement any custom Windows message handlers (say, by overriding WndProc or
PreProcessMessage methods)?

If you will be able to see the "msg" structure contents, you'll find out the
exact message that causes the data grid to fail.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
news:1a1201c372e0$fba15180$a501280a@phx.gbl...
> I've tried the rest bu with no results.
>
> The stacktrace is:
>
> ******** Begin Exception ********
> "System.NullReferenceException: Object reference not set
> to an instance of an object.
> 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 CO.Win.MainModule.Main() in
> C:\CODev\Utveckling\CO\CO.Win\Main.vb:line 128"
> ******** End Exception ********
>
>
> >-----Original Message-----
> >1. Have you tried the rest of my suggestions?
> >2. Try to look at the stack trace after stopping program
> execution upon
> >NullReferenceException. This might help you figure out
> the approximate error
> >location - compare the method names in the stack trace
> with those you have
> >overridden, for example.
> >
> >--
> >Dmitriy Lapshin [C# / .NET MVP]
> >X-Unity Test Studio
> >http://x-unity.miik.com.ua/teststudio.aspx
> >Bring the power of unit testing to VS .NET IDE
> >
> >"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
> >news:197f01c372c7$446e8d20$a601280a@phx.gbl...
> >> I've tried "Stop when an exeption occurs" but it doesnt
> >> help.
> >>
> >> The nullreferenceexception occurs before i even started
> >> editing och clicking the datagrid.
> >>
> >> The consequences of this exception is that this mission
> >> ciritical application crasch.
> >>
> >> What to do?
> >>
> >> Thanks in advance!
> >
> >.
> >


Re: NullReferenceException by Mats-Erik

Mats-Erik
Fri Sep 05 01:11:50 CDT 2003

Is the "msg" structure data saved in the
nullreferenceexception exception?

>-----Original Message-----
>The stack trace eventually points to a Windows message
handler. Do you
>implement any custom Windows message handlers (say, by
overriding WndProc or
>PreProcessMessage methods)?
>
>If you will be able to see the "msg" structure contents,
you'll find out the
>exact message that causes the data grid to fail.
>
>--
>Dmitriy Lapshin [C# / .NET MVP]
>X-Unity Test Studio
>http://x-unity.miik.com.ua/teststudio.aspx
>Bring the power of unit testing to VS .NET IDE
>
>"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
>news:1a1201c372e0$fba15180$a501280a@phx.gbl...
>> I've tried the rest bu with no results.
>>
>> The stacktrace is:
>>
>> ******** Begin Exception ********
>> "System.NullReferenceException: Object reference not set
>> to an instance of an object.
>> 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 CO.Win.MainModule.Main() in
>> C:\CODev\Utveckling\CO\CO.Win\Main.vb:line 128"
>> ******** End Exception ********
>>
>>
>> >-----Original Message-----
>> >1. Have you tried the rest of my suggestions?
>> >2. Try to look at the stack trace after stopping
program
>> execution upon
>> >NullReferenceException. This might help you figure out
>> the approximate error
>> >location - compare the method names in the stack trace
>> with those you have
>> >overridden, for example.
>> >
>> >--
>> >Dmitriy Lapshin [C# / .NET MVP]
>> >X-Unity Test Studio
>> >http://x-unity.miik.com.ua/teststudio.aspx
>> >Bring the power of unit testing to VS .NET IDE
>> >
>> >"Mats-Erik Grundh" <classe@Classeabc.se> wrote in
message
>> >news:197f01c372c7$446e8d20$a601280a@phx.gbl...
>> >> I've tried "Stop when an exeption occurs" but it
doesnt
>> >> help.
>> >>
>> >> The nullreferenceexception occurs before i even
started
>> >> editing och clicking the datagrid.
>> >>
>> >> The consequences of this exception is that this
mission
>> >> ciritical application crasch.
>> >>
>> >> What to do?
>> >>
>> >> Thanks in advance!
>> >
>> >.
>> >
>
>.
>

Re: NullReferenceException by Dmitriy

Dmitriy
Fri Sep 05 02:09:57 CDT 2003

No, it is not. I just hope you would be able to inspect this structure when
you double click the corresponding row in the Stack Trace. That's how the
debugger works - it can inspect variables only from current context, and
contexts are switched when you double-click in the Stack Trace window.
Unfortunately, I can't be 100% sure of this - I don't do such an advanced
debugging frequently.

Anyway, I think the first things to be throughly checked are:

- Custom painting
- Custom keyboard handling
- Custom mouse handling

As you have said you experience this error even when you don't edit or
navigate the grid, custom painting would be the first candidate, I think.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
news:1bc201c37374$983fbb60$a101280a@phx.gbl...
> Is the "msg" structure data saved in the
> nullreferenceexception exception?
>
> >-----Original Message-----
> >The stack trace eventually points to a Windows message
> handler. Do you
> >implement any custom Windows message handlers (say, by
> overriding WndProc or
> >PreProcessMessage methods)?
> >
> >If you will be able to see the "msg" structure contents,
> you'll find out the
> >exact message that causes the data grid to fail.
> >
> >--
> >Dmitriy Lapshin [C# / .NET MVP]
> >X-Unity Test Studio
> >http://x-unity.miik.com.ua/teststudio.aspx
> >Bring the power of unit testing to VS .NET IDE


Re: NullReferenceException by Mats-Erik

Mats-Erik
Fri Sep 05 04:31:00 CDT 2003

The only row left in the stacktrace window is currentrow.

There are no owner drawn/overide paint, keaybord or
mousehandling in the form.

1. clickes an ordinary Button
2. in buttons click event i call a sub that catch data
from server.
3. i create a ordinary new datagrid with custom
columnstyles.
4. assign datatable to datagrid.



>-----Original Message-----
>No, it is not. I just hope you would be able to inspect
this structure when
>you double click the corresponding row in the Stack
Trace. That's how the
>debugger works - it can inspect variables only from
current context, and
>contexts are switched when you double-click in the Stack
Trace window.
>Unfortunately, I can't be 100% sure of this - I don't do
such an advanced
>debugging frequently.
>
>Anyway, I think the first things to be throughly checked
are:
>
>- Custom painting
>- Custom keyboard handling
>- Custom mouse handling
>
>As you have said you experience this error even when you
don't edit or
>navigate the grid, custom painting would be the first
candidate, I think.
>
>--
>Dmitriy Lapshin [C# / .NET MVP]
>X-Unity Test Studio
>http://x-unity.miik.com.ua/teststudio.aspx
>Bring the power of unit testing to VS .NET IDE
>
>"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
>news:1bc201c37374$983fbb60$a101280a@phx.gbl...
>> Is the "msg" structure data saved in the
>> nullreferenceexception exception?
>>
>> >-----Original Message-----
>> >The stack trace eventually points to a Windows message
>> handler. Do you
>> >implement any custom Windows message handlers (say, by
>> overriding WndProc or
>> >PreProcessMessage methods)?
>> >
>> >If you will be able to see the "msg" structure
contents,
>> you'll find out the
>> >exact message that causes the data grid to fail.
>> >
>> >--
>> >Dmitriy Lapshin [C# / .NET MVP]
>> >X-Unity Test Studio
>> >http://x-unity.miik.com.ua/teststudio.aspx
>> >Bring the power of unit testing to VS .NET IDE
>
>.
>

Re: NullReferenceException by Dmitriy

Dmitriy
Fri Sep 05 04:36:18 CDT 2003

> 3. i create a ordinary new datagrid with custom
> columnstyles.

What exactly these column styles customize? I am pretty sure the problem is
one of these column styles - I have had similar unpredictable exceptions
myself and they were definitely related to bugs in the custom column styles.

More on that - do you follow the correct order of table style/column style
creation given in MSDN?

> 4. assign datatable to datagrid.

How to you do that? I'd suggest sticking to the SetDataBinding method.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
news:1d8001c37390$6ad0cea0$a101280a@phx.gbl...
> The only row left in the stacktrace window is currentrow.
>
> There are no owner drawn/overide paint, keaybord or
> mousehandling in the form.
>
> 1. clickes an ordinary Button
> 2. in buttons click event i call a sub that catch data
> from server.
> 3. i create a ordinary new datagrid with custom
> columnstyles.
> 4. assign datatable to datagrid.
>
>
>
> >-----Original Message-----
> >No, it is not. I just hope you would be able to inspect
> this structure when
> >you double click the corresponding row in the Stack
> Trace. That's how the
> >debugger works - it can inspect variables only from
> current context, and
> >contexts are switched when you double-click in the Stack
> Trace window.
> >Unfortunately, I can't be 100% sure of this - I don't do
> such an advanced
> >debugging frequently.
> >
> >Anyway, I think the first things to be throughly checked
> are:
> >
> >- Custom painting
> >- Custom keyboard handling
> >- Custom mouse handling
> >
> >As you have said you experience this error even when you
> don't edit or
> >navigate the grid, custom painting would be the first
> candidate, I think.
> >
> >--
> >Dmitriy Lapshin [C# / .NET MVP]
> >X-Unity Test Studio
> >http://x-unity.miik.com.ua/teststudio.aspx
> >Bring the power of unit testing to VS .NET IDE
> >
> >"Mats-Erik Grundh" <classe@Classeabc.se> wrote in message
> >news:1bc201c37374$983fbb60$a101280a@phx.gbl...
> >> Is the "msg" structure data saved in the
> >> nullreferenceexception exception?
> >>
> >> >-----Original Message-----
> >> >The stack trace eventually points to a Windows message
> >> handler. Do you
> >> >implement any custom Windows message handlers (say, by
> >> overriding WndProc or
> >> >PreProcessMessage methods)?
> >> >
> >> >If you will be able to see the "msg" structure
> contents,
> >> you'll find out the
> >> >exact message that causes the data grid to fail.
> >> >
> >> >--
> >> >Dmitriy Lapshin [C# / .NET MVP]
> >> >X-Unity Test Studio
> >> >http://x-unity.miik.com.ua/teststudio.aspx
> >> >Bring the power of unit testing to VS .NET IDE
> >
> >.
> >