title: Application Insights Exceptions and Failures
body: <p>I'm trying to work with Application Insights in the Azure preview portal and with Visual Studio 2015 Community edition.  I'm encountering three different problems which I suspect are all related.  I'm wondering if others are encountering these issues.</p>
  
  <p>In one of my test web applications, the App-Insight tool is partially working.  In another I'm getting errors concerning irretrievable data.  In the third, I'm running into deployment failures when I use App-Insight with resources in a new resource group.  </p>
  
  <p>I will present all three in this question, because I suspect they may all have the same root cause.</p>
  
  <h2>Partial Results</h2>
  
  <p>The very first app I tried to retrofit with app-insight does actually work and display app-insight telemetry...or at least it mostly works.  Half the telemetry data shows, and the rest does not make it.</p>
  
  <p><img src="https://mail.google.com/mail/u/0/?ui=2&amp;ik=a4dc27db28&amp;view=fimg&amp;th=15017e13ec9553f4&amp;attid=0.0.1&amp;disp=emb&amp;realattid=ii_15017e06748cd106&amp;attbid=ANGjdJ-1W2ROP2fmurEEchaSZoBDsku7a8dgN2h_2QYjJhLVse4HX9fVsYes-FjSllu_EbnE2avmfUrP7-0261C8Qcozfsfgzalz6SbgGVgVk3QS1xUdpmkjSeT0woc&amp;sz=w1068-h458&amp;ats=1443561874363&amp;rm=15017e13ec9553f4&amp;zw&amp;atsh=1" alt="telemetry"></p>
  
  <p>The sequence of setting this up was as follows:</p>
  
  <p>I started by installing the <a href="https://msdn.microsoft.com/en-us/magazine/mt147241.aspx" rel="noreferrer">sample Mobile-MVC app that came with this MSDN Magazine article</a>, from June 2015.  After fiddling around with adding bootstrap to make responsive pages, I then decided to commit the code to VS online GIT and then deploy as an Azure web app.</p>
  
  <p>I then followed instructions to <a href="https://azure.microsoft.com/en-us/documentation/articles/web-sites-enable-diagnostic-log/#how-to-view-logs-in-application-insights" rel="noreferrer">View logs in Application Insights</a> and ran the application which succeeds in launching a browser and allowing me to interact with the site.  However, during this exercise I get tons of exceptions showing in the Visual Studio output window.  I've included a small snippet here, where I've bolded the most interesting two pieces:</p>
  
  <blockquote>
    <p>Exception thrown: 'System.MethodAccessException' in Microsoft.ApplicationInsights.Extensibility.DependencyCollector.dll
    Exception thrown: 'System.TypeInitializationException' in Microsoft.ApplicationInsights.Extensibility.DependencyCollector.dll
    Exception thrown: 'System.TypeInitializationException' in Microsoft.ApplicationInsights.Extensibility.DependencyCollector.dll
    <strong>ApplicationInsightsHttpModule failed at initialization with exception: System.TypeInitializationException: The type initializer for 'Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource' threw an exception. ---> System.MethodAccessException: Attempt by method 'Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource..ctor()' to access method 'Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.ApplicationNameProvider..ctor()' failed.</strong><br>
       at Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource..ctor()
       at Microsoft.ApplicationInsights.Extensibility.DependencyCollector.Tracing.DependencyCollectorEventSource..cctor()
       --- End of inner exception stack trace ---
       at Microsoft.ApplicationInsights.Extensibility.DependencyCollector.DependencyTrackingTelemetryModule.Initialize(TelemetryConfiguration configuration)
       at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.InitializeComponents(IEnumerable components, TelemetryConfiguration configuration)
       at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.InitializeComponents(TelemetryConfiguration configuration)
       at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.Initialize(TelemetryConfiguration configuration)
       at Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.get_Active()
       at Microsoft.ApplicationInsights.Extensibility.Web.ApplicationInsightsHttpModule..ctor()</p>
    
    <p><strong>[msg=Log Error];[msg=System.TypeLoadException: Could not load type 'Microsoft.ApplicationInsights.Channel.JsonSerializer' from assembly 'Microsoft.ApplicationInsights, Version=1.2.0.5639, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.</strong>
       at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetrySerializer.d__0.MoveNext()
       at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine&amp; stateMachine)
       at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetrySerializer.SerializeAsync(IEnumerable<code>1 items)
       at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetryBuffer.&lt;&gt;c__DisplayClass5.&lt;FlushAsync&gt;b__3()
       at System.Threading.Tasks.Task</code>1.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.ApplicationInsights.Extensibility.Web.Implementation.TelemetryBuffer.d__7.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.ApplicationInsights.Extensibility.Implementation.TaskTimer.&lt;>c__DisplayClass1.&lt;b__0>d__3.MoveNext()]</p>
  </blockquote>
  
  <p>My Azure portal is receiving telemetry on some things, but not others.  In short, the ability to produce telemetry is crippled, as suggested by the above exceptions.</p>
  
  <p>Now for the next problem.</p>
  
  <h2>New Resource Group</h2>
  
  <p>Using the preview portal, I created a brand new resource group called "SandBox".  Again using the preview portal, I then made a brand new web application called "ScratchWeb" which I assigned to the "Sandbox" resource group. </p>
  
  <p>The deployment of the web resource eventually completes, but there is an associated application insight resource called ""Microsoft.WebSite3cb98c31-893c"" that automatically is created which experiences a dozen or so time-out errors before it eventually is declared as a failed deployment.  Below I show an example of one of the timeout errors, as well as the final error which gives some key information.</p>
  
  <pre><code>Operation Id
  1E2094CECE6531F1
  Tracking Id
  31283062-9061-4dcf-bd42-f9885abbf596
  Status
  GatewayTimeout
  Provisioning State
  Running
  Timestamp
  ‎9‎/‎28‎/‎2015‎ ‎10‎:‎37‎:‎59‎ ‎PM
  Duration
  PT30.7117477S
  Type
  microsoft.insights/components
  Resource Id
  /subscriptions/da769a1f-78d8-4d45-b9b3-c15ea0c89ca2/resourceGroups/SandBox/providers/microsoft.insights/components/ScratchWeb
  StatusMessage
  {"code":"GatewayTimeout","message":"Request timed out","innererror":{"diagnosticcontext":"034b642f-aece-494b-9ede-f8b015f5bfeb","time":"2015-09-29T05:37:59.8355234Z","data":"d0fe44bb-8317-4359-bf2c-160f1eb00433"}}
  Resource
  ScratchWeb
  </code></pre>
  
  <p>And here is the final failure error message:</p>
  
  <pre><code>Operation Id
  1E2094CECE6531F1
  Tracking Id
  08dbbf0a-0d4a-4692-9b1a-3603a984d40d
  Status
  Conflict
  Provisioning State
  Failed
  Timestamp
  ‎9‎/‎28‎/‎2015‎ ‎10‎:‎48‎:‎16‎ ‎PM
  Duration
  PT10M47.5300298S
  Type
  microsoft.insights/components
  Resource Id
  /subscriptions/da769a1f-78d8-4d45-b9b3-c15ea0c89ca2/resourceGroups/SandBox/providers/microsoft.insights/components/ScratchWeb
  StatusMessage
  {"code":"The component already existed in a different resource group.","message":"The component already existed in a different resource group.","innererror":{"diagnosticcontext":"9ea42d3d-4dbf-46e8-a188-eac09a4ddb09","time":"2015-09-29T05:48:15.7282268Z"}}
  Resource
  ScratchWeb
  </code></pre>
  
  <p>Is this because the "Application Insights" preview is not capable of running in more than one resource group, or is it because my subscription doesn't allow it? </p>
  
  <p>The weirdest part is that once the deployment of the app-insights resource FINALLY failed, it nevertheless seems to have been created and is not visible inside my Application Insights resource collection.</p>
  
  <p>Now the last problem...</p>
  
  <h2>Original Resource Group</h2>
  
  <p>If I try to create a new web site in my <em>existing</em>, default web app resource group...then none of the aforementioned problems occurs.  Unfortunately I get another problem.  The "application insight" resource blade tells me "error retrieving data" when it tries to show me charts.  On the other hand, Visual Studio tells me that everything is fine...it says something like "congratulations, you have published you first app insight data."</p>
  
  <p><img src="https://mail.google.com/mail/u/0/?ui=2&amp;ik=a4dc27db28&amp;view=fimg&amp;th=15017e13ec9553f4&amp;attid=0.0.3&amp;disp=emb&amp;realattid=ii_15017de830899c73&amp;attbid=ANGjdJ98dMdaJ6352cmYnkUaGSxf5vQRJOT0W62iyjl_EV50tD0KR60DkuDA3Yign4ZGfo8x743ZEBwypvKYBtF4HzAqljYuH_1b5m4LOSiGzvV9M0jlfGNyFuzPSK4&amp;sz=w762-h122&amp;ats=1443561874362&amp;rm=15017e13ec9553f4&amp;zw&amp;atsh=1" alt="no data">
  <img src="https://mail.google.com/mail/u/0/?ui=2&amp;ik=a4dc27db28&amp;view=fimg&amp;th=15017e13ec9553f4&amp;attid=0.0.2&amp;disp=emb&amp;realattid=ii_15017df34974226e&amp;attbid=ANGjdJ8MVsQyDFgfhkdpaASc0Lko-BPLWM6H__EmgXOPfpKioIIll5KmU7_aJBPpQmdGdZC13Tf9oYwB795mMu2rbrH7wkvYkdmRnOi1lHswkcP1r4yBgP_Jro5Mvnw&amp;sz=w976-h150&amp;ats=1443561874363&amp;rm=15017e13ec9553f4&amp;zw&amp;atsh=1" alt="no data"></p>
  
  <p>So, in the end, I have only one web application with viewable App-Insight results, and those results are crippled.  My attempt to create a 2nd working web app with app-insight was unsuccessful regardless if I used an existing resource group or tried a new one.</p>
  
  <p>With Visual Studio 2015 I used two different approaches to try adding the App-Insight SDK.  I tried adding it to my web project after-the-fact, and I also tried adding it from a new project template.  The only scenario where I got <em>anything</em> to work is when I instrumented my first web app "after-the-fact" with the App-Insight SDK.  Unfortunately (1) those results were crippled and (2) as I've described above, I can't achieve even "crippled" results a second time.  Thus right now the App-Insight capability is unworkable for me.</p>