7

当我为我的 ASP.Net Core 1.1 应用程序启用 BrowserLink 时,我在浏览器中收到以下错误,我认为因为 BrowserLink 不起作用。

Browser Link: Exception thrown when trying to invoke Browser Link extension callback "microsoft.visualstudio.web.browserlink.sourcemappingextensionfactory.getCssMappingData":
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.VsWebUrlUtil.EnsureAbsoluteUrl(IVsHierarchy hierarchy, Uri& path)
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.VsWebUrlUtil.GetSimpleVsWebUrlFromUrl(IVsHierarchy hierarchy, Uri url, ILocationContainer& container)
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.VsWebUrlUtil.GetVsWebUrlFromUrl(IVsHierarchy hierarchy, Uri url)
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.LazyLocationContainer.LazyLocationContainerFromUrl.CreateActualLocationContainer()
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.LazyLocationContainer.GetPhysicalPath(Uri& physicalPath)
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.DocumentLocation.Microsoft.VisualStudio.Web.Extensions.Common.Helpers.IDocumentLocation.GetPhysicalPath(Uri& physicalPath)
   at Microsoft.VisualStudio.Web.BrowserLink.SourceMappingExtension.getCssMappingData(String cssUrl, String[] selectors)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.VisualStudio.Web.BrowserLink.ClientMessaging.DispatchMessage(BrowserLinkConnection connection, MessageArgs obj)

Browser Link: Exception thrown when trying to invoke Browser Link extension callback "microsoft.visualstudio.web.browserlink.autosyncextensionfactory.trackCssDocuments":
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.VsWebUrlUtil.EnsureAbsoluteUrl(IVsHierarchy hierarchy, Uri& path)
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.VsWebUrlUtil.GetSimpleVsWebUrlFromUrl(IVsHierarchy hierarchy, Uri url, ILocationContainer& container)
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.VsWebUrlUtil.GetVsWebUrlFromUrl(IVsHierarchy hierarchy, Uri url)
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.LazyLocationContainer.LazyLocationContainerFromUrl.CreateActualLocationContainer()
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.LazyLocationContainer.GetPhysicalPath(Uri& physicalPath)
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.DocumentLocation.Microsoft.VisualStudio.Web.Extensions.Common.Helpers.IDocumentLocation.GetPhysicalPath(Uri& physicalPath)
   at Microsoft.VisualStudio.Web.Extensions.Common.Helpers.DocumentLocation.Microsoft.VisualStudio.Web.Extensions.Common.Helpers.IDocumentLocation.get_PhysicalFileExists()
   at Microsoft.VisualStudio.Web.BrowserLink.AutoSyncExtension.trackCssDocuments(String[] trackHrefs, String[] untrackHrefs)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.VisualStudio.Web.BrowserLink.ClientMessaging.DispatchMessage(BrowserLinkConnection connection, MessageArgs obj)

Browser Link: Failed to invoke return value callback:
TypeError: Cannot read property 'files' of null

我已将我的应用程序配置如下:

.csproj 配置:

<ItemGroup>
    <PackageReference Include="AutoMapper" Version="5.2.0" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="1.2.0" />
    <PackageReference Include="BundlerMinifier.Core" Version="2.4.337" />
    <PackageReference Include="IdentityModel" Version="2.5.1" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" PrivateAssets="All" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" PrivateAssets="All" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
    <PackageReference Include="Serilog.Extensions.Logging.File" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
</ItemGroup>

<Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
    <Exec Command="bower install" />
    <Exec Command="dotnet bundle" />
</Target>

在我调用的 Configure 方法的 Startup.cs 文件中app.UseBrowserLink();

更新

似乎该错误与 *.css 文件有关。如果我删除所有 CSS 链接,我只会收到以下错误:

Browser Link: Failed to invoke return value callback:
TypeError: Cannot read property 'files' of null
4

2 回答 2

2

在使用 VS2017 在 .NET Core 中搜索浏览器链接的修复程序时,我首先进入了这个线程。

我所缺少的只是

app.UseBrowserLink();

在 Startup.csConfigure方法中。

请参阅Visual Studio 2015 Update 3 中的 ASP.NET Core v1.0 的浏览器链接

(这可能更适合作为评论,但我没有足够的代表。)

于 2017-08-24T11:29:18.427 回答
1

我通过删除默认的 browserlink 包解决了这个问题

Microsoft.VisualStudio.Web.BrowserLink

并安装

Microsoft.VisualStudio.Web.BrowserLink.Loader

Microsoft 文档的本指南中提到了此包。不知道有什么区别,但它似乎解决了我的问题。

于 2017-05-19T03:23:25.040 回答