PresentationTraceSources null reference exception

Jun 10, 2010 at 5:58 PM
Edited Jun 10, 2010 at 7:45 PM

I get a null reference exception when I try to snoop my application using source from snoopwpf-47581.  The application I am running is a Prism based application. Our application presents a logon window before running the primary window.  I can snoop the logon window but after authenticating and the Prism bootstrapper loads the shell and enumerates the modules I get the following null reference exception.

Here is the stack.

System.NullReferenceException occurred
  Message=Object reference not set to an instance of an object.
  Source=mscorlib
  StackTrace:
       at System.Object.GetType()
       at System.Diagnostics.FilterElement.RefreshRuntimeObject(TraceFilter filter)
       at System.Diagnostics.ListenerElement.RefreshRuntimeObject(TraceListener listener)
       at System.Diagnostics.TraceSource.Refresh()
       at System.Diagnostics.TraceSource.RefreshAll()
       at System.Diagnostics.Trace.Refresh()
       at System.Diagnostics.PresentationTraceSources.Refresh()
       at Snoop.SnoopUI..ctor() in C:\Users\anwalker\Downloads\snoopwpf-47581\WPF4\Snoop 2.5\Snoop\SnoopUI.xaml.cs:line 56
  InnerException:

There are a few more peculiarities that we deal with.  In the Main we check for single instance based upon the file location of the application the user is running. 

The odd thing is that I can fix the problem by commenting out all calls to PresentationTraceSources namespace in SnoopUI.xaml,cs and PropertyInformation.cs.  After these changes I can successfully snoop the shell window of my application.

I am not sure if I can create a test application that would be helpful in debugging the issue.  I am running a 64bit application and 64bit snoop on a Windows 7 64bit box on .NET 4.

Andy

Coordinator
Jun 10, 2010 at 7:26 PM
Edited Jun 10, 2010 at 7:27 PM

Interesting. I've never seen a problem with PresentationTraceSources before.

Is this a new issue? That is, have previous versions of Snoop worked for you? I speculate that they haven't.

Can you Snoop if you wait till the main shell has been loaded (meaning ... don't Snoop the login window but wait till the main shell comes up)?

I know you said it might be difficult, but could you try to create a simple test application? If we find a fix, it is very helpful as I go to integrate that fix. But, besides it would also allow me to take a look at this myself.

Jun 10, 2010 at 10:31 PM

Well I have tried to put together a similar application but cannot get the same behavior.  Makes me concerned about how we are initializing our application.  I have a work around for now...  If I have any luck tracking down the cause I will pass along the knowledge.

Thanks for the response.

Dec 3, 2010 at 9:37 AM
andywalkers wrote:

Well I have tried to put together a similar application but cannot get the same behavior.  Makes me concerned about how we are initializing our application.  I have a work around for now...  If I have any luck tracking down the cause I will pass along the knowledge.

Thanks for the response.

Hi,

I encountered exactly the same problem. Are there any new findings concerning this issue? Also I would be happy to hear what caused the issue and what was your workaround.

Best regards,
Carsten

Coordinator
Dec 4, 2010 at 1:20 AM

There have been no new findings on this issue ... I would love to get a hold of a simple test harness that illustrates this issue. Can you put one together? If so, I will debug in on it. If you can't, try debugging it yourself.

Post back here, too, if you discover any solutions.

Nov 25, 2014 at 2:24 PM
I am running into almost the same stack trace in .NET 4.0 without using snoop. We are using an XBAP application hosted in IE. In looking at the code, there appears to be a problem when the Trace.Refresh() is called at runtime. Specifically we call this so all Trace's will get notified to refresh themselves due to a configuration change. I've not be able to resolve this issue yet myself, but it appears to be tied in to the TraceFilters some how. Don't know if this will help in the case of snoop or not, but believe this is a .NET Framework bug in the Trace code.

at System.Diagnostics.FilterElement.RefreshRuntimeObject(TraceFilter filter)
at System.Diagnostics.ListenerElement.RefreshRuntimeObject(TraceListener listener)
at System.Diagnostics.TraceSource.Refresh()
at System.Diagnostics.TraceSource.RefreshAll()
at System.Diagnostics.Trace.Refresh()
at CustomApp.InstrumentationViewModel.UpdateAppSettings()