Re: UnsafeNativeMethods.DispatchMessageA throwing an exception



TDC wrote:
We've got hunderdes of installs of varying sizes of our software over
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.

Errors that mysteriously manifest themselves in places they shouldn't be manifesting is usually indicative of a global corruption issue unrelated to the error site.

Using Reflector I can see that this coming from deep within the bowls
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.

Yes, 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.

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.
.



Relevant Pages

  • Re: Manday for Web Pentest
    ... I'm finding that this is highly dependent upon the customer. ... For reporting, my ratio for 5 days is 3 days reporting. ... I always try to have an application walk through with the app team to ... the efford estimation method among the whole team. ...
    (Pen-Test)
  • Re: how to find out code
    ... Well, part of the problem is that you reported a "crash", which is a pretty meaningless ... more useless than reporting "a crash" without all the important information associated ... If this is happening at a customer site, ... is so obviously an illegal address that the assumption is that you had a NULL pointer. ...
    (microsoft.public.vc.mfc)
  • Re: Manday for Web Pentest
    ... One way to formalize it is to find out the customer is willing to pay, ... For reporting, my ratio for 5 days is 3 days reporting. ... I always try to have an application walk through with the app team to ... the efford estimation method among the whole team. ...
    (Pen-Test)
  • Re: Webservice question
    ... The Accounts represent a customer on our existing Database (personal ... with a C# dll. ... Using the dll approach would require each customer to have a copy of the ... Not sure why you'd want your own web front end to access the web service. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Circular Reference Problem
    ... whilst I could re-engineer with an extra dll that both projects refer to, ... I have a "customer" object that contains a form that displays customer ... >why your CMN project requires access to your PRD project. ...
    (microsoft.public.dotnet.languages.vb)

Quantcast