Azure function Application Insights Object reference not set to an instance of an object

Azure function Application Insights Object reference not set to an instance of an object
Home » Technology » .Net » Azure function Application Insights Object reference not set to an instance of an object

Table of contents

Below we will explain how to solve the error “Object reference not set to an instance of an object” that appears when running an Azure function with Application Insights installed.

Error description

As we have already mentioned, we found the error when running an Azure function with Application Insights installed.

Specifically, the error is in the AzureAppServiceRoleNameFromHostNameHeaderInitializer class, Initialize method, line “if (telemetry == null)”.

The exception we found is the following:

at Microsoft.ApplicationInsights.AspNetCore.TelemetryInitializers.AzureAppServiceRoleNameFromHostNameHeaderInitializer.Initialize(ITelemetry telemetry)

Object reference not set to an instance of an object.

How to fix the error?

The solution is simple, we just have to add the following two lines to local.settings.json in the “Values” section:

"HOST_NAME": "localhost ",
"APPINSIGHTS_INSTRUMENTATIONKEY": "11111111-2222-3333-4444-555555555555"

So that the final result of our local.settings.json file is the following: