Skip to content
This repository has been archived by the owner on Apr 11, 2020. It is now read-only.

BrowserLink does not work for ASP.NET Core on Visual Studio 2017 RTM #1015

Open
Eilon opened this issue Mar 9, 2017 · 19 comments
Open

BrowserLink does not work for ASP.NET Core on Visual Studio 2017 RTM #1015

Eilon opened this issue Mar 9, 2017 · 19 comments

Comments

@Eilon
Copy link
Member

Eilon commented Mar 9, 2017

From @mrtaikandi on March 9, 2017 12:22

I'm not sure if this is the right repo for this issue.
I get the following error in the browser when I enable BrowserLink for my ASP.Net Core 1.1 application and I think because of that the BrowserLink does not work.

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

I have configured my App as follow:

.csproj config:

<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>

And in the Startup.cs file in Configure method I have called app.UseBrowserLink();.

UPDATE

It seems the error is related to the *.css files. If I remove all my CSS links I only get the following error:

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

Copied from original issue: aspnet/Mvc#5933

@Eilon
Copy link
Member Author

Eilon commented Mar 9, 2017

From @pranavkm on March 9, 2017 14:5

cc @barrytang \ @YangLyu89

@Eilon
Copy link
Member Author

Eilon commented Mar 9, 2017

From @DamianEdwards on March 9, 2017 16:5

I can certainly reproduce that Browser Link doesn't work in a brand new project in VS2017 RTM. This is what I see in the Chrome debug console:
image

@mrtaikandi
Copy link

I have to add that I was created this project using VS2015 with preview 2 tooling and with that I was only got the TypeError: Cannot read property 'files' of null error. After migrating to MSBuild by VS2017 RTM I am getting the above error.

@mrtaikandi
Copy link

Any news on this issue?

@RassulYunussov
Copy link

I generate a project using CLI
dotnet new mvc
then try to start

dotnet restore
dotnet run

And I get an error

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

When i change the package reference to Browser link inside my csproj file to an older version

<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.0.1" />

I can successfully run my aspnet mvc web application.

My environment:

dotnet --version
1.0.1
dotnet --info
.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.12
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/1.0.1

@barrytang
Copy link

@mlorbetske, can you take a look?

@mlorbetske
Copy link

@RassulYunussov please try clearing your NuGet cache, you can do with with the command line
dotnet nuget locals all --clear, then set the environment variable DOTNET_SKIP_FIRST_TIME_EXPERIENCE to 1, and then run dotnet restore on the project - this will force the set of packages needed by the template to be downloaded fresh from NuGet. You may then clear the environment variable that lets the CLI do its first time experience.

@RassulYunussov
Copy link

@mlorbetske Thank You! It solved my problem!

@rezamohamed
Copy link

Seeing the same issue. @mlorbetske can you clarify the steps for VS2017 please? Where do you set that Environment Variable?

@do0om
Copy link

do0om commented Apr 29, 2017

I have the same issue on VS 2017 15.1 with an Asp.net Core 1.1 app 👍

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

Is there a fix for this issue?

@mlorbetske
Copy link

@rezamohamed in Visual Studio, simply go to Tools -> Options -> NuGet Package Manager -> General and click the Clear All NuGet Cache(s) button. After it completes, dismiss the Tools -> Options dialog, right click on the solution containing the project and select Restore NuGet Packages. This will cause VS to populate the package cache. Later, if the CLI does its first run experience, the good BrowerLink package will not be overwritten - no environment variables required.

@jodavis any ideas about what @do0om is seeing?

@dotnetshadow
Copy link

I'm still seeing the same issue, tried the steps above about clearing nuget but still doesn't work
This happens on multiple machines VS 2017 15.1 with an Asp.net Core 1.1 app

image

@do0om
Copy link

do0om commented May 6, 2017

I used the last browser reload on save extension referenced in this related issue.
I still have the same error message for browserlink but everything is working except reload on save for cshtml files but this is not a browserlink issue.

@genusP
Copy link

genusP commented May 22, 2017

Any news on this issue?

@cgountanis
Copy link

This is still an issue with latest tooling and Firefox Developer. Any word on this or where do we go? I can not stand Chrome's restore last page error every single load and Firefox Developer is much easier to use for most things.

@egmfrs
Copy link

egmfrs commented Aug 24, 2017

I found this page when googling for a fix for browserlink in .net core vs2017 and I thought the fact this issue was still open meant it was simply not compatible with .net core / vs2017.
However, all I was missing was app.UseBrowserLink(); from the Startup.cs Configure method.
Hope that helps someone in the same boat I was in.

@ghost
Copy link

ghost commented Sep 1, 2017

I am seeing this error in Internet Explorer 11, but my browser is refreshing as expect when I either press ctrl+alt+enter, use the toolbar button with my mouse - and even automatically on file save since I have installed the extension Browser Reload on Save. I'm using Visual Studio 2017 15.3.3 and I am using an ASP.NET Core 2.0 web application project.

@vaindil
Copy link

vaindil commented Oct 13, 2017

None of the solutions thus far have worked for me. I'm calling app.UseBrowserLink() in Startup.cs and I have UseIISIntegration() in Program.cs. This is ASP.NET Core 2.0 in VS 2017 Professional. Console output is below.

image

The text of the actual errors is here.

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.
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.
Browser Link: Failed to invoke return value callback:
TypeError: Cannot read property 'files' of null

@GearTheWorld
Copy link

2017-10-24 18_39_03-expensesaccountcore - microsoft visual studio

I confirm it's not working. Maybe it's the way I'm using it ?

Visual Studio 2017 Version 15.3.5

The scenario is as follow :

Add a html page to the project.
Do some stuff on it to visualise something you know !
Then hit RIGHT CTRL-SHIFT-F5 to load the page without debugger.
Look your marvel and then go destroy (modify) it and go back to the browser.

Nothing changed. Need to hit F5 in the browser to see the change and yes the setting for that is on as shown on the provided screenshot

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests