Open jhlgns opened 3 years ago
I‘ve been experiencing similar behavior on my 2017 Mac Book Pro, running macOS 11.6.
I have the same problem with my Setup
Does this happen to anybody else? Unfortunately, the development of my project stalled because of this. Any help is appreciated!
Thanks everyone. Does this happen for the default (new) app or for specific application?
@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.
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
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)
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"
}
}
}
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
@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.
Adding script
<script src="/_framework/aspnetcore-browser-refresh.js"></script>
worked for me!
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.
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.
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!
Description
I have a solution consisting of 3 projects:
dotnet watch run
running in a terminal next to my editor. Sometimes when I change files (does not matter of which project), the dotnet watch process hangs up. The last output often looks something like this:The second file with the 4 digit numeric filename is only displayed when I use Vim I think, but the hangup happens independently of the editor. I think its filename is always 4913 and it apparently comes from the same directory as the file that got changed. When I hit Ctrl-C, this gets printed:
Typing "reset" (while no characters are appearing in the console) fixes the broken terminal problem, but it happens quite frequently. Sometimes it happens many times in a row, and at other times I can make ~5 changes without it hanging up.
Regression?
Since dotnet 5 did not have hot-reload capabilities, these problems did not exist back when we were using dotnet 5. When I create a new blazorwasm project using
dotnet new blazorwasm -o TestProject
hot reloading and everything works as expected. I have rewrittenProperties/launchSettings.json
, copied it over from a freshly created blazor WASM project because my only guess was the problems originated from there. Also I tried to set hotReloadProfile in launchSettings.json to any possible value I could find in the web, used the profile explicitly withdotnet watch run --profile ...
, but none of that had an effect.Other information
When
dotnet watch run
detects a change and rebuilds the backend, the blazor WASM application does not reload at all. The blazor error UI appears at the bottom of the page and this exception gets printed to the browser console:Edit:
I should mention that I am running
dotnet watch run
in the directory of Secret.Api (which is hosting Secret.WebApp). When runningdotnet watch run
in Secret.WebApp (which shows some CORS errors for obvious reasons but they don't matter so far for testing), the page at least reloads when a razor page or component is modified. But still no hot reload and still throwing exceptions. This gets then printed to the browser console (now it is a index out of bounds error, not NullReferenceException):Before any error is shown, this gets printed to the browser console:
Where the port in the connection error seems to be random. Immediately following this: