Application Information

I have two projects: one is an MVC4 application, and the other is an output type class library.

I want to make the second project (class library) a layer for understanding.

The code compiles and the server is working fine.

public static void SaveMetric(string title, double value, string azureKey, Dictionary<string, string> properties = null) { try { TelemetryClient telemetry = new TelemetryClient(); telemetry.InstrumentationKey = azureKey; telemetry.TrackMetric(title, value, properties); } catch (Exception ex) { var a = ""; } } 

The problem starts when I call the telemetry.TrackMetric function. This code returns an error:

"The reference to the object is not installed in the instance of the object." (System.NullReferenceException exception).

Can I use Microsoft Insights in a class library project? And if so, what am I doing wrong?

+5
source share
2 answers

Going deep into my search for solutions, I found that the problem was in the update I made (version 1.0 - 1.2). The solution was to downgrade the software to version 1.0.

0
source

I recently upgraded to 1.2.0 and ran into the same problem. In addition to the standard setup, my code redefined the toolkit key in ApplicationInsights.config one saved in web.config . This was done using global.asax - Application_Start . The code works fine locally, but when deployed to Azure, it runs.

Turns out that was the problem of how I accessed web.config . I had to switch the code from WebConfigurationManager to ConfigurationManager .

This Application_Start code:

 Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = System.Web.Configuration.WebConfigurationManager.AppSettings["MyInstrumentationKey"]; 

changed to this:

 Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = System.Configuration.ConfigurationManager.AppSettings["MyInstrumentationKey"]; 
+2
source

All Articles