locked
Null Reference Exception in TelemeteryClient.Track() RRS feed

  • Question

  • AppInsights for .NET Web Apps v0.17.0 (.NET Web Apps)

    I've been attempting to get Exception Tracking working on Azure using one of our existing projects.

    Using the standard call:

    var ai = new TelemetryClient();
    ai.TrackException(exception);

    This all works fine locally, but when it gets deployed to Azure I get this

    Exception information: 
        Exception type: NullReferenceException 
        Exception message: Object reference not set to an instance of an object.
       at Microsoft.ApplicationInsights.TelemetryClient.Track(ITelemetry telemetry)
       at Microsoft.ApplicationInsights.TelemetryClient.TrackException(ExceptionTelemetry telemetry)
       at Microsoft.ApplicationInsights.TelemetryClient.TrackException(Exception exception, IDictionary`2 properties, IDictionary`2 metrics)

    I've tried several different combinations of the TelemetryClient.Track related methods and always get the same exception. The normal client side page view tracking works great, it's just the exception tracking that is failing.

    Any advice on this would be greatly appreciated.

    Edit: I just updated to v1.0 and still have the issue.



    Thursday, June 25, 2015 2:02 PM

Answers

  • I think I've fixed it.

    Our Azure packaging process was putting the wrong .dll in the approot bin folder.

    packages\Microsoft.ApplicationInsights.1.0.0\lib\wp8\Microsoft.ApplicationInsights.dll

    instead of 

    packages\Microsoft.ApplicationInsights.1.0.0\lib\net40\Microsoft.ApplicationInsights.dll

    Even though the WP8 .dll is never referenced in the project.

    I've removed the WP8 folder and that fixes the problem.


    Friday, June 26, 2015 2:05 PM

All replies

  • Hey Liam,

    Which SDK of application insights are you using?

    Thanks,

    Meni Zalzman

    Thursday, June 25, 2015 2:17 PM
  • ApplicationInsights for .NET Web Apps
    Thursday, June 25, 2015 2:21 PM
  • do you have applicationInsights.config file in you project? if so can you share it with me?

    Thanks,

    Meni Zalzman

    Thursday, June 25, 2015 2:48 PM
  • <?xml version="1.0" encoding="utf-8"?>
    <ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
      <!-- 
        Learn more about Application Insights configuration with ApplicationInsights.config here: 
        http://go.microsoft.com/fwlink/?LinkID=513840
        
        Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file.
      -->
      <TelemetryModules>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.RuntimeTelemetry.RemoteDependencyModule, Microsoft.ApplicationInsights.Extensibility.RuntimeTelemetry"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCollector.PerformanceCollectorModule, Microsoft.ApplicationInsights.Extensibility.PerfCollector">
          <!--
          Use the following syntax here to collect additional performance counters:
          
          <Counters>
            <Add PerformanceCounter="\Process(??APP_WIN32_PROC??)\Handle Count" ReportAs="Process handle count" />
            ...
          </Counters>
          
          PerformanceCounter must be either \CategoryName(InstanceName)\CounterName or \CategoryName\CounterName
          
          Counter names may only contain letters, round brackets, forward slashes, hyphens, underscores, spaces and dots.
          You may provide an optional ReportAs attribute which will be used as the metric name when reporting counter data.
          For the purposes of reporting, metric names will be sanitized by removing all invalid characters from the resulting metric name.
          
          The following placeholders are supported as InstanceName:
            ??APP_WIN32_PROC?? - instance name of the application process  for Win32 counters.
            ??APP_W3SVC_PROC?? - instance name of the application IIS worker process for IIS/ASP.NET counters.
            ??APP_CLR_PROC?? - instance name of the application CLR process for .NET counters.
          -->
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryModules.WebRequestTrackingTelemetryModule, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryModules.WebExceptionTrackingTelemetryModule, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryModules.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.ApplicationInsights.Extensibility.Web"/>
      </TelemetryModules>
      <!-- 
        Learn more about Application Insights configuration with ApplicationInsights.config here: 
        http://go.microsoft.com/fwlink/?LinkID=513840
        
        Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file.
      -->
      <TelemetryChannel Type="Microsoft.ApplicationInsights.Web.Channel.TelemetryChannel, Microsoft.ApplicationInsights.Web.TelemetryChannel"/>
      <!-- 
        Learn more about Application Insights configuration with ApplicationInsights.config here: 
        http://go.microsoft.com/fwlink/?LinkID=513840
        
        Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file.
      -->
      <ContextInitializers>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.ContextInitializers.BuildInfoConfigComponentVersionContextInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.ContextInitializers.DeviceContextInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
      </ContextInitializers>
      <TelemetryInitializers>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryInitializers.WebSyntheticTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryInitializers.WebClientIpHeaderTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryInitializers.WebUserAgentTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryInitializers.WebOperationNameTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryInitializers.WebOperationIdTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryInitializers.WebUserTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryInitializers.WebSessionTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryInitializers.AzureRoleEnvironmentTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.Web.TelemetryInitializers.DomainNameRoleInstanceTelemetryInitializer, Microsoft.ApplicationInsights.Extensibility.Web"/>
      </TelemetryInitializers>
    </ApplicationInsights>

    Our Instrumentation Key is defined in a separate config file and initialized in code:

    private void ConfigureTelemetry()
    {
        if (ApplicationInsightsSetting.DisableTelemetry)
        {
             TelemetryConfiguration.Active.DisableTelemetry = true;
             return;
        }
    
         TelemetryConfiguration.Active.InstrumentationKey = ApplicationInsightsSetting.InstrumentationKey;
         TelemetryConfiguration.Active.ContextInitializers.Add(new HdTelemetryInitializer());
    }
    public class HdTelemetryInitializer : IContextInitializer
    {
        public void Initialize(TelemetryContext context)
        {
            context.Component.Version = GetType().Assembly.GetName().Version.ToString();
        }
    }



    Thursday, June 25, 2015 2:54 PM
  • Hello Liam,

    I tried reproducing the issue according the code snippets you gave and I am not getting the null reference exception, I think I am missing something can you contact me at meniz@microsoft.com

    Thanks,

    Meni Zalzman

    Friday, June 26, 2015 1:49 PM
  • I think I've fixed it.

    Our Azure packaging process was putting the wrong .dll in the approot bin folder.

    packages\Microsoft.ApplicationInsights.1.0.0\lib\wp8\Microsoft.ApplicationInsights.dll

    instead of 

    packages\Microsoft.ApplicationInsights.1.0.0\lib\net40\Microsoft.ApplicationInsights.dll

    Even though the WP8 .dll is never referenced in the project.

    I've removed the WP8 folder and that fixes the problem.


    Friday, June 26, 2015 2:05 PM