4
votes

I am starting to explore Application Insights and tried adding it to my Windows Phone 8.1 app. While trying to execute the project, an exception is thrown on load within Public Sub New() in App.xaml.vb. The line where the error happens is

TelemetryClient = new TelemetryClient()

The exception thrown is

A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll

An exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll but was not handled in user code

Additional information: Exception has been thrown by the target of an invocation.

Innerexception details:

{System.InvalidOperationException: Type 'Microsoft.ApplicationInsights.Extensibility.ComponentContextInitializer, Microsoft.ApplicationInsights, Version=0.16.1.418, Culture=neutral, PublicKeyToken=31bf3856ad364e35' does not implement the required interface

Microsoft.ApplicationInsights.Extensibility.IContextInitializer. at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.CreateInstance(Type interfaceType, String typeName) at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.LoadInstance(XElement definition, Type expectedType, Object instance) at Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryConfigurationFactory.LoadInstances[T](XElement definition, ICollection`1 instances)}

I followed the steps outlined in the Azure documentation. What may I be doing wrong?

2
What was the InnerException? TargetInvocationException always has one. (It tells you what actually happened in the reflectively invoked method.) Seeing some other code in New() might also help us.Ben N
I have added the innerexception details for reference. As for other code within New(), this is the first line, followed by InitializeComponent()Jay
Is your debugger set to break on first-chance exceptions? What happens if you just have execution continue after the exception is thrown?Ben N
I believe it is turned off, but I may be wrong. None of the 'Thrown' is checked in my debugger settings. If I continue, the app crashes without executing the next line of code.Jay

2 Answers

0
votes

Are you using a Windows Phone app on top of Windows Runtime or on top of Silverlight?

If you remove the following line from ApplicationInsights.config, does your app start successfully?

    <Add Type="Microsoft.ApplicationInsights.Extensibility.ComponentContextInitializer, Microsoft.ApplicationInsights"/>
0
votes

Turns out it was a corrupted solution. I had added the nuget and then added the Application Insights. In between I had upgraded the nugget package to the 0.16 pre-release version. In effect it had created multiple references. So I ended up manually clearing all entries of Microsoft.ApplicationInsights in package.config and .vbproj. I also removed all the references and referenced the whole thing again. Now it works like a charm!