Re: UnsafeNativeMethods.DispatchMessageA throwing an exception
- From: Jeroen Mostert <jmostert@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 20:18:42 +0100
TDC wrote:
We've got hunderdes of installs of varying sizes of our software overErrors that mysteriously manifest themselves in places they shouldn't be manifesting is usually indicative of a global corruption issue unrelated to the error site.
the years that have never reported a problem, but we've got a single
high-profile customer reporting that our software is crashing with:
System.NullReferenceException: Object reference not set to an instance
of an object.
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageA(MSG&
msg)
etc, etc
Obviously this is bubbling up from within the framework, making it
hard to pinpoint the real source.
Here's the background information:
The bulk of the software resides in a COM dll (well, actually many
dlls but the object model hides that detail).
When our software runs as a Application (as decided by the user when
they installed), the COM dll is hosted by a headless ActiveX server.
When our software runs as a Windows Service, the COM dll is hosted by
our .NET Windows Service process. To accomplish this, our service
layer creates a dedicated STA thread to instanciate the root (and only
publicly exposed) COM object. The STA thread then sets up the message
pump via a call to Application.Run(Context).
What we are seeing in the event log is that Application.Run is
aborting with the exception I indicated above. It doesn't seem to
happen often, the software is reported to run for days, and as
mentioned earlier it runs at other (often smaller) customer sites with
no problems.
Using Reflector I can see that this coming from deep within the bowlsYes, it can. In .NET 1, a structured exception with code STATUS_ACCESS_VIOLATION is translated to a NullReferenceException by the marshaller. This is confusing, so .NET 2 introduced the AccessViolationException to clearly distinguish these from actual null dereferences. So you're really seeing an access violation here, not anything involving managed objects.
of the message pumping subsystem within the .NET Framework (v1.1 by
the way), and since DispatchMessageA is a native method I was really
surprised that a .NET NullReferenceException could buble back from it.
I could use some help troubleshooting this one, it's a doosey!
Well, something in memory is definitely corrupt, but the cause is another matter.
It could be heap corruption, but if you've got hundreds of installations that ran fine for years, that would be less likely, and debugging this is not trivial. Still, it's a distinct possibility. Vet your code carefully for memory issues. If it's an option to ship a debug version to your customer to resolve the issue, you might try that.
You could also ask your customer to run a memory test on the server (memtest86+ comes highly recommended here). This may be hard to sell (programmers are often accused of yelling "hardware problem!" when it's not, after all), but broken memory (say a single bit error) can cause extremely subtle problems that are impossible to reproduce anywhere else, but consistently happen on that one machine.
--
J.
.
- References:
- Prev by Date: Re: Interop Troubleshooting
- Next by Date: Re: UnsafeNativeMethods.DispatchMessageA throwing an exception
- Previous by thread: UnsafeNativeMethods.DispatchMessageA throwing an exception
- Next by thread: Re: UnsafeNativeMethods.DispatchMessageA throwing an exception
- Index(es):
Relevant Pages
|