dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.59k stars 10.06k forks source link

dotnet watch stops detecting changes, crashes and corrupts terminal #37462

Open jhlgns opened 3 years ago

jhlgns commented 3 years ago

Description

I have a solution consisting of 3 projects:

wafab112 commented 3 years ago

I‘ve been experiencing similar behavior on my 2017 Mac Book Pro, running macOS 11.6.

timhahlganss commented 3 years ago

I have the same problem with my Setup

jhlgns commented 3 years ago

Does this happen to anybody else? Unfortunately, the development of my project stalled because of this. Any help is appreciated!

mkArtakMSFT commented 3 years ago

Thanks everyone. Does this happen for the default (new) app or for specific application?

jhlgns commented 3 years ago

@mkArtakMSFT This happened in two independent dotnet 6 blazorwasm projects. The default empty app seems to be working fine regarding hot reload.

Also, I made many attempts to fix the bug, including commenting out some relevant parts of the code, changing configuration files and looking at the dotnet source code to get some context of why this could be happening. I could not figure anything out. dotnet watch would seemingly randomly hang up and crash no matter what I did.

GiffenGood commented 3 years ago

Same issue when I upgraded my Asp.net Hosted Blazor app to 6.0.0.

Error: System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.ApplyHotReloadDelta(String moduleIdString, Byte[] metadataDelta, Byte[] ilDeta) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) --- End of stack trace from previous location --- at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson) at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime jsRuntime, DotNetInvocationInfo& invocationInfo, String argsJson) at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson) at Object._convert_exception_for_method_ca

amlutgen commented 3 years ago

I experienced the same issue when running dotnet watch on an Blazor WASM app that was just upgraded to 6.0 on Windows 10. The UI did not update at all and instead an unhandled error appeared at the bottom of the page and the console was showing the error:

Error: System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.ApplyHotReloadDelta(String 
moduleIdString, Byte[] metadataDelta, Byte[] ilDeta)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
--- End of stack trace from previous location ---
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
   at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(JSRuntime jsRuntime, DotNetInvocationInfo& invocationInfo, String argsJson)
   at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
rwobig93 commented 3 years ago

I ended up running into the same issue when migrating my Blazor wasm app over to .net 6. I stumbled upon the dotnet watch tutorial page for .net 6: https://docs.microsoft.com/en-us/aspnet/core/tutorials/dotnet-watch?view=aspnetcore-6.0 At the very bottom is a section talking about browser refresh and dotnet watch injecting a .js script (which I ended up putting into index.html) and this got hot reload working via dotnet watch for me, it however did not fix hot reload working in VS 2022 directly so my workaround atm is to explicitly use dotnet watch via the debug profile by using the SwitchStartupProject VS extension.

The script section they refer to that worked for me was this:

@* _Layout.cshtml -or- index.html *@
<environment names="Development">
    <script src="/_framework/aspnetcore-browser-refresh.js"></script>
</environment>

And call dotnet watch in the launchsettings.json (w/o run, adding run seems to break hot reload again by thinking no files are actually changed for whatever reason):

{
  "profiles": {
    "Peiskos.Server": {
      "commandName": "Executable",
      "executablePath": "C:\\Program Files\\dotnet\\dotnet.exe",
      "commandLineArgs": "watch",
      "workingDirectory": "C:\\Users\\Rick\\source\\repos\\rwobig93\\Peiskos\\src\\Server",
      "launchUrl": "https://localhost:5001",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "dotnetRunMessages": "true"
    }
  }
}
erbatista commented 3 years ago

I was able to solve this issue for me with the following two steps:

1 Trust the dev certificate if you don't have done so: dotnet dev-certs https --trust 2 Firefox users like me, need to create a policy to trust IIS Express/Kestrel developer certificates, instructions here

GiffenGood commented 3 years ago

@pranavkm rwobig93

In my case this did not change the result. I could see in the network tools that aspnetcore-browser-refresh.js was already being injected, prior to adding. After adding, it was just downloaded twice.

IonRobu commented 2 years ago

Adding script <script src="/_framework/aspnetcore-browser-refresh.js"></script> worked for me!

ghost commented 2 years ago

Thanks for contacting us. We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. Because it's not immediately obvious that this is a bug in our framework, we would like to keep this around to collect more feedback, which can later help us determine the impact of it. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

ghost commented 1 year ago

To learn more about what this message means, what to expect next, and how this issue will be handled you can read our Triage Process document. We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. Because it's not immediately obvious what is causing this behavior, we would like to keep this around to collect more feedback, which can later help us determine how to handle this. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact work.

wdemars commented 6 months ago

We just experienced this same issue after some solution refactoring. We fixed a minor JavaScript file references and added the fix identified by @IonRobu above. Working again!