升级到.NET Core 1.1.1后,ASP.NET Core MVC应用程序见解停止工作 [英] ASP.NET Core MVC application insights stopped working after upgrade to .NET Core 1.1.1
问题描述
2016年12月,我有一个简单的ASP.NET Core应用程序正在使用.它可以很好地与应用程序见解和遥测结合使用.
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.
现在四个月后,我想开始这项工作,并开始从.NET Core 1.1.0升级到1.1.1.在此过程中,软件包Microsoft.ApplicationInsights.AspNetCore
从版本1.0.2
更新到了版本2.0.0
.
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"
屏幕:
从project.json升级到新的csproj并使用新的Visual Studio 2017没有帮助.
Upgrade from project.json to new csproj and using new Visual Studio 2017 doesn't help.
看来ApplicationInsightsJavaScript已从API中基本删除.那我该如何启用javascript应用程序见解?
It looks like ApplicationInsightsJavaScript was basically removed from API. How do I enable javascript application insights then?
推荐答案
从ApplicationInsights 1.x到2.x的重大更改已在GitHub
There are breaking changes from ApplicationInsights 1.x to 2.x which are documented on GitHub release notes.
- 此版本包含对SDK内部的重写,以实现更好的.NET 核心集成和初始化.
UseApplicationInsightsRequestTelemetry
已过时,它使用的逻辑 现在将自动处理要执行的操作,并调用此方法 应该从Startup.cs中删除.UseApplicationInsightsExceptionTelemetry
已过时,异常 遥测现在在内部自动处理.你应该删除 从Startup.cs对此方法的调用,否则您将得到重复 报告了异常遥测.- JavaScript的MVC依赖项 代码段已被删除,以便包含JavaScript代码段 现在您需要进行以下更改:
- 在_ViewImports.cshtml中,将
@inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration
替换为@inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
- 在_Layout.cshtml中替换
@Html.ApplicationInsightsJavaScript(TelemetryConfiguration)
和@Html.Raw(JavaScriptSnippet.FullScript)
- 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)
这篇关于升级到.NET Core 1.1.1后,ASP.NET Core MVC应用程序见解停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!