Spontaneous 'Object reference not set to an instance of an object.

G

Guest

Hello,

We run .NET Application on Citrix environment. We use VB.NET, Framework
..NET 1.1. SP1.
Rarely, we get an exception without any obvious reason. Most of the time,
the user does not even work with the application (It is running on background
while he/she is writing a mail for example) or does nothing at all – just
staring at the monitor!
Our working version is that the GC needs more memory and when it tries to
free some resources – something goes wrong. We tried to force this exception
with collecting memory (System.GC.Collect()) - no success. We are going to
try running a separate program which allocates a lot of memory so the GC will
be forced to find some memory.
Please, any ideas, what might cause it (or even better – how to avoid it)
are very welcome since we are running out of ours.

Thanks
Kiril

The Exception is:

Exception: Object reference not set to an instance of an object.
Source: System.Windows.Forms
Call Stack:
at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg,
HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
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)


Some times it is slightly different:

at System.Windows.Forms.UnsafeNativeMethods.GetMessageW(MSG& msg,
HandleRef hWnd, Int32 uMsgFilterMin, Int32 uMsgFilterMax)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
....(The rest is the same)

or:

at System.Windows.Forms.TimerProc.Invoke(IntPtr hWnd, Int32 msg, IntPtr
wParam, IntPtr lParam)
at System.Windows.Forms.UnsafeNativeMethods.GetMessageW(MSG& msg,
HandleRef hWnd, Int32 uMsgFilterMin, Int32 uMsgFilterMax)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
...(The rest is the same)
 
G

Guest

rHi Kiril,

We have similar problems, and have tracked down a couple of causes so far
but so far have not completely eliminated the problem.

1. The ToolTip class was causing this problem in most cases we had reported
to us. Since implementing a fix the problem occurs far less frequently. A bug
was introduced in .NET 1.1 SP1 to do with the clean-up code of the ToolTip,
and in certain conditions it can manifest itself as a seemingly random
NullReferenceException. I can post the code we're using as a work-around if
anyone would find this useful.

2. We had a WindowsHook that was being cleaned up when disposing, but wasn't
being cleaned up during finalization. Any time the object wasn't disposed
properly, a NullReferenceException could potentially occur when the callback
was invoked by windows (the object that owned the callback had been collected
by the GC).

One of your callstacks looks like you're using the
System.Windows.Forms.Timer class. I would look closely into situation where
your Timers are being finalized instead of disposed - I think if your Timers
are disposed instead of finalized then you shouldn't receive this error.
Maybe :) That you describe the problem manifesting itself spontaneously is
another clue that it may be related to a Timer.

Can you reproduce the problem on your testing machines or has it only
happened to your users? Can you create a cut down version of your application
and still reproduce the problem?

Hope this helps.

Regards,
Matt Garven
 
G

Guest

Hi Matt!

Thanks for the answer. Your question as follow:
I can post the code we're using as a work-around if
anyone would find this useful.

1.Please! I am very interested in, since we use ToolTip. ïŒ I guest we could
stop using it at all but the client kind a like it.

2.WindowsHooks: We use it and that’s the first think we checked and that was
one of the reasons. Now it happens less frequently but unfortunately it still
DOES happened form time to time.
One of your callstacks looks like you're using the
System.Windows.Forms.Timer class.
I know, but believe it or not we don’t use timers at all. (I wouldn’t belive
having seen this exception)
Can you reproduce the problem on your testing machines or has it only
happened to your users? Can you create a cut down version of your application
and still reproduce the problem?
We haven’t been able to reproduce it, so far. Unfortunately we tested it on
one developer machine which runs WinXP whereas the production Citrix
environment runs Win2003 Server. We are planning to make application, which
is going to consume as much as possible resources while our application is
still running. The idea is to run both applications on our test Citrix
machine.

Once again thanks a lot.
Kiril

P.S. Please, post the work-around for the ToolTip.
 

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