Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core MVC application insights stopped working after upgrade to .NET Core 1.1.1

I have one simple ASP.NET Core application I was working on back in December 2016. It worked just fine with application insights and telemetry.

Now after 4 months I wanted to pick up this work and started with upgrade from .NET Core 1.1.0 to 1.1.1. In this process package Microsoft.ApplicationInsights.AspNetCore got updated from version 1.0.2 to version 2.0.0.

This unfortunately caused my app to stop working, in particular I get this error:

An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.

/Views/Shared/_Layout.cshtml

'IHtmlHelper<dynamic>' does not contain a definition for 'ApplicationInsightsJavaScript' and no extension method 'ApplicationInsightsJavaScript' accepting a first argument of type 'IHtmlHelper<dynamic>' could be found (are you missing a using directive or an assembly reference?)
+
    @Html.ApplicationInsightsJavaScript(TelemetryConfiguration)

Show compilation source
#pragma checksum "/Views/Shared/_Layout.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "050a2afdfb4a44e17be72e76627a3d3a0d0b7d5a"
namespace AspNetCore
{
#line 1 "/Views/_ViewImports.cshtml"

Screen:

enter image description here

Upgrade from project.json to new csproj and using new Visual Studio 2017 doesn't help.

It looks like ApplicationInsightsJavaScript was basically removed from API. How do I enable javascript application insights then?

like image 815
Pawel Troka Avatar asked Apr 28 '17 14:04

Pawel Troka


People also ask

How do you integrate application insights in .NET core?

Open your project in Visual Studio. Go to Project > Add Application Insights Telemetry. Choose Azure Application Insights, then select Next. Choose your subscription and Application Insights instance (or create a new instance with Create new), then select Next.

Does .NET core support MVC?

Model validationASP.NET Core MVC supports validation by decorating your model object with data annotation validation attributes. The validation attributes are checked on the client side before values are posted to the server, as well as on the server before the controller action is called.

How do I enable application insights?

Select Application Insights in the left pane for your app service. Then select Enable. Create a new resource or select an existing Application Insights resource for this application. When you select OK to create a new resource, you're prompted to Apply monitoring settings.

How do I add applications insights to .NET framework?

Add Application Insights automatically From within your ASP.NET web app project in Visual Studio: Select Project > Add Application Insights Telemetry > Application Insights Sdk (local) > Next > Finish > Close.


1 Answers

There are breaking changes from ApplicationInsights 1.x to 2.x which are documented on GitHub release notes.

  • This release contains a rewrite of the SDK internals for better .NET Core integration and initialization.
  • UseApplicationInsightsRequestTelemetry is obsolete, the logic it used to perform is handled automatically now and calls to this method should be deleted from Startup.cs.
  • UseApplicationInsightsExceptionTelemetry is obsolete, exception telemetry is handled automatically internally now. You should delete calls to this method from Startup.cs otherwise you will get duplicate exception telemetry reported.
  • The MVC dependency for the JavaScript snippet has been removed so in order to include the JavaScript snippet now you need to make the following changes:
    • In _ViewImports.cshtml replace @inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration with @inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
    • In _Layout.cshtml replace @Html.ApplicationInsightsJavaScript(TelemetryConfiguration) with @Html.Raw(JavaScriptSnippet.FullScript)
like image 173
Tseng Avatar answered Sep 19 '22 16:09

Tseng