I'm playing with Application Insights (AI) to try and see if I can log and view exceptions thrown by my application.
I've followed this guide to setup a new MVC project linked to a new AI resource in Azure for testing purposes. Everything works pretty well.
After I've read the following guide to Diagnose failures & exceptions, I've created a new action method where I'm triggering a NullReferenceException
. I really love how this telemetry data is send to AI. When debugging the application, I can view the exception thrown in Visual Studio inside the Application Insights Search window. It gives me the following stacktrace:
System.NullReferenceException: Object reference not set to an instance of an object.
at WebApplicationInsights.Controllers.HomeController.Error (HomeController.cs:33) (WebApplicationInsights, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null)
at lambda_method (Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)
at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
.
.
at System.Web.HttpApplication.ExecuteStep (System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
As you can see, the exception is raised from the HomeController.
Now after publishing to Azure, I've raised this exception again by visiting the live website. Examining the exception in the Azure Portal I'm getting this stacktrace:
System.NullReferenceException:
at lambda_method (Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null)
at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)
.
.
at System.Web.HttpApplication.ExecuteStep (System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
You can observe that the last call in the stacktrace is missing. Why?
The exception thrown while debugging locally is also present in the Azure Portal, however this one is not missing that last call. See this screenshot:
Additional question: what does Anonymously Hosted DynamicMethods Assembly
represent in the stacktrace and why is it there?