0
votes

This is in a Visual Studio Solution with an Asp.Net MVC app targeting .NET Framework 4.6 as the UI project, and several other C# class library projects.

We Application Insights Nuget packages, including the Snapshot Collector package, to all the projects in the solution we wish to trace. All Nuget packages use the latest version.

To trigger a snapshot from code, I throw an exception like so:

try
{
     throw new Exception("This is an AI test exception");
}
catch (Exception ex)
{
     var ai = new TelemetryClient();
     var props = new Dictionary<string, string> { { "Property1", "A test property value" } };
     ai.TrackException(ex, props);
}

The MVC Project's ApplicationInsights.config is configured as follows

<TelemetryProcessors>
    <Add Type="Microsoft.ApplicationInsights.SnapshotCollector.SnapshotCollectorTelemetryProcessor, Microsoft.ApplicationInsights.SnapshotCollector">
      <IsEnabledInDeveloperMode>false</IsEnabledInDeveloperMode>
      <HandleUntrackedExceptions>true</HandleUntrackedExceptions>
      <ThresholdForSnapshotting>1</ThresholdForSnapshotting>
      <ProblemCounterResetInterval>2.00:00:00</ProblemCounterResetInterval> <!--2 days-->
    </Add>
</TelemetryProcessors>

I published the app to Azure and invoked the exception several times by browsing the App.

This setup results in the exception being recorded to Application Insights, but without the snapshot. Snapshots work fine for unhandled exceptions.

Shouldn't it take a snapshot after the exception occurs a second time?

1
As in my side, I tried your code in my side and when I debug, it can successfully trigger the snapshot. https://i.stack.imgur.com/qqYjJ.png. So if you still face the issue, please try to 1) disable any vs installed extensions under Extensions-->Manage Extensions 2) reset vs settings under Tools-->Import and Export Settings--> Reset all settings 3) delete bin and obj folder. 4) or you could create a new asp net mvc project to test whether the issue happens in the new one. - Mr Qian
I will try that, thanks. It's good to know this is supposed to work. - Christopher J. Grace
We will wait for your any response:) - Mr Qian

1 Answers

1
votes

Please try the following steps:

1) change your IsEnabledInDeveloperMode to true in ApplicationInsights.config file.

true means that it will enable Snapshot Debugging.

<IsEnabledInDeveloperMode>true</IsEnabledInDeveloperMode>

2) add this before your code to check if there is an error loading the assembly.

var _ = typeof(SnapshotCollectorTelemetryProcessor);

3) add bindredirect in your web.config file:

<dependentAssembly>
        <assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="xxxxx" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-2.15.0.44797" newVersion="2.15.0.44797"/>
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="Microsoft.ApplicationInsights.SnapshotCollector" publicKeyToken="xxxx" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-1.3.7.0" newVersion="1.3.7.0" />
</dependentAssembly>

Usually, the activities will be in the %temp% folder.

If these do not work,

a) disable any vs installed extensions under Extensions-->Manage Extensions

b) reset vs settings under Tools-->Import and Export Settings--> Reset all settings

c) delete .vs hidden folder, bin and obj folder.