Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot Reload unavailable #47836

Closed
1 task done
wf-soft opened this issue Apr 22, 2023 · 15 comments · Fixed by #48953
Closed
1 task done

Hot Reload unavailable #47836

wf-soft opened this issue Apr 22, 2023 · 15 comments · Fixed by #48953
Assignees
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external)

Comments

@wf-soft
Copy link

wf-soft commented Apr 22, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am using the latest VS2022 17.6.0 Preview 4.0

The preview version created the BlazorServer project, and all hot reloads were invalidated without any prompt. I am unable to determine the reason

dotnet watch ⌚ File changed: C:\Users\wf-so\Downloads\HotReloadIssue45519Demo-main\HotReloadIssue45519Demo-main\TradeCars\Client\Pages\Index.razor.
dotnet watch ⌚ No hot reload changes to apply.
dotnet watch 🔥 Hot reload capabilities: Baseline AddMethodToExistingType AddStaticFieldToExistingType NewTypeDefinition ChangeCustomAttributes.
dotnet watch ⌚ File changed: C:\Users\wf-so\Downloads\HotReloadIssue45519Demo-main\HotReloadIssue45519Demo-main\TradeCars\Client\Pages\Index.razor.
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/2 POST https://localhost:5008/_framework/blazor-hotreload application/json 2835
dotnet watch ⌚ Received 0 from browser in [Count: 1, MessageType: Binary, EndOfMessage: True].
dotnet watch ⌚ Received failed apply from delta applier.
  ❔ Do you want to restart your app - Yes (y) / No (n) / Always (a) / Never (v)?

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

dotnet-sdk-7.0.203

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label Apr 22, 2023
@amcasey amcasey added the feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) label May 19, 2023
@szalapski
Copy link

szalapski commented Jun 5, 2023

This is a direct successor to #45519, which was closed with "Likely fixed by dotnet/sdk#31015.", but it was not fixed. I wish someone would have tested it with the provided example before deeming it "likely fixed". The test is very easy.

Here's the minimal example, the same one that was provided in #45519, now upgraded to use SDK 7.0.302

szalapski/HotReloadIssue45519Demo

Clone this and run

dotnet watch --verbose --project ./TradeCars/Server

The site should start up. You'll see Hot reload capabilities: . which portends the failure. Edit anything in Index.razor to watch hot reload fail.

Please get Hot Reload to work reliably and consistently with Blazor WebAssembly (and Blazor Server, likely the same problem), especially with changes to .razor files. This feature seems so buggy when it should "just work". It seems to work much better with non-Blazor server-side changes, e.g. to a Web API, but that's not where much productivity benefit would result.

When using dotnet watch on my Server project, with verbose logging , I get watch : Hot reload capabilities: . (not even Baseline) and, on a change, No hot reload changes to apply. (when there are). This is with .NET 7.0.5 and SDK 7.0.302 on a solution that was created with .NET 6 and recently upgraded to 7.

Starting...
dotnet watch 🔥 Hot reload capabilities: .
dotnet watch ⌚ File changed: .\MySoln\Client\Shared\MainLayout.razor.
dotnet watch ⌚ No deltas modified. Applying changes to clear diagnostics.
dotnet watch ⌚ Received 1 from browser in [Count: 1, MessageType: Binary, EndOfMessage: True].
dotnet watch ⌚ No hot reload changes to apply.
dotnet watch 🔥 Hot reload change handled in 4092.6926ms.

When running from VS (with or without debugging), I get similar output:
image, or sometimes instead "Your debugged process might be corrupted and restarting it is recommended nearly always."

See also:

Seems like there are a lot of others struggling too but not commenting in GitHub issues, e.g.

Expected Behavior

  • dotnet watch hot reload should just work. I don't want to see "No hot reload changes to apply."
  • If it isn't working and thus I get "watch : Hot reload capabilities: .", I'd like to see output that tells me why in the verbose output (indeed, perhaps even in warnings).

@szalapski
Copy link

@wf-soft Can I recommend you edit the title of this issue to read:

Hot Reload nearly always fails, with Blazor and "dotnet watch"

That will get it more attention and more closely link it to #45519.

@danroth27
Copy link
Member

Adding @phil-allen-msft @maddymontaquila and @mcumming for visibility.

@tmat
Copy link
Member

tmat commented Jun 21, 2023

I see this error in the browser with the latest .NET 8:

Updated repro project:
Net8.zip

 at System.Reflection.Metadata.MetadataUpdater.ApplyUpdate(Assembly assembly, ReadOnlySpan`1 metadataDelta, ReadOnlySpan`1 ilDelta, ReadOnlySpan`1 pdbDelta)
   at Microsoft.Extensions.HotReload.HotReloadAgent.ApplyDeltas(IReadOnlyList`1 deltas)
   at Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.ApplyHotReloadDelta(String moduleIdString, Byte[] metadataDelta, Byte[] ilDelta, Byte[] pdbBytes)
   at System.Reflection.MethodInvoker.InterpretedInvoke(Object obj, IntPtr* args)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
--- 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, Int64 dotNetObjectId, String argsJson)
   at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.__Wrapper_InvokeDotNet_1772498872(JSMarshalerArgument* __arguments_buffer)
Error: The assembly can not be edited or changed.
    at yr (https://localhost:5008/_framework/dotnet.runtime.8.0.0-preview.6.23316.2.dk1nh2rbrm.js:3:35896)
    at Uo (https://localhost:5008/_framework/dotnet.runtime.8.0.0-preview.6.23316.2.dk1nh2rbrm.js:3:53691)
    at Object.<anonymous> (https://localhost:5008/_framework/dotnet.runtime.8.0.0-preview.6.23316.2.dk1nh2rbrm.js:3:52482)
    at Object.invokeDotNetFromJS (https://localhost:5008/_framework/blazor.webassembly.js:1:43350)
    at b.invokeDotNetMethod (https://localhost:5008/_framework/blazor.webassembly.js:1:3485)
    at b.invokeDotNetStaticMethod (https://localhost:5008/_framework/blazor.webassembly.js:1:3241)
    at Wt.Ye._internal.applyHotReload (https://localhost:5008/_framework/blazor.webassembly.js:1:52017)
    at https://localhost:5008/_framework/aspnetcore-browser-refresh.js:140:35
    at Array.forEach (<anonymous>)
    at applyBlazorDeltas (https://localhost:5008/_framework/aspnetcore-browser-refresh.js:138:14)
(anonymous) @ aspnetcore-browser-refresh.js:142
applyBlazorDeltas @ aspnetcore-browser-refresh.js:138
BlazorHotReloadDeltav1 @ aspnetcore-browser-refresh.js:46
connection.onmessage @ aspnetcore-browser-refresh.js:53

@tmat
Copy link
Member

tmat commented Jun 21, 2023

@lambdageek

@lambdageek
Copy link
Member

@tmat I can repro that failure if I have VS Code editing the project (I have the C# Dev Kit installed). I get different results if I edit with Emacs or vim. In general The assembly can not be edited or changed. can happen if:

  1. the DOTNET_MODIFIABLE_ASSEMBLIES=debug environment variable is not set in the client-side runtime
  2. or the baseline assembly does not have the "optimizer disabled" attribute (essentially the assembly was compiled in Release mode, not Debug)

There's definitely something here. I'll try to get some more info

@lambdageek
Copy link
Member

lambdageek commented Jun 21, 2023

@tmat yea, I don't see that The assembly can not be edited or changed. error if I disabled the C# Dev Kit extension in VS Code

Update
If I just have ms-dotnettools.csharp (v2.0.238) enabled, I dont' have the apply update exception when I try to make changes to Client/Pages/Index.razor
If I also enable ms-dotnettools.csdevkit (v0.1.103) then I get "the assembly can not be edited or changed" if I run dotnet watch --verbose --project ./TradeCars/Server and then edit the client Index.razor page.

@tmat
Copy link
Member

tmat commented Jun 21, 2023

This change will communicate the error message to dotnet-watch and print it out, for easier diagnostics in future: dotnet/sdk#33471

@lambdageek
Copy link
Member

This should improve the "assembly cannot be edited or changed" error message dotnet/runtime#87880

@tmat
Copy link
Member

tmat commented Jun 21, 2023

@szalapski
We found that the issue is with launchSettings.json configuration. The value of ASPNETCORE_ENVIRONMENT should be Development, not Developer. Then builder.Environment.IsEnvironment("Developer") in Program.cs also needs to be updated.

After these changes Hot Reload works.

We certainly need to improve the error reporting.

@szalapski
Copy link

szalapski commented Jun 21, 2023

We use "Developer" for local machines and "Development" for a deployed dev environment. Is there any way to get it to work? The docs say that we can use any value we want for Environment so i'd hope there's a way.

@tmat
Copy link
Member

tmat commented Jun 21, 2023

@szalapski Not currently, but fixing that: #48953

Meanwhile you may consider changing developer -> development and development -> deployed, or something like that.

@szalapski
Copy link

szalapski commented Jun 22, 2023

Thanks @tmat. I got rid of the notion of "Developer" in my demo app, instead using "Development", and I modified Program.cs accordingly, and I still see no change. I still get dotnet watch ⌚ No hot reload changes to apply. Would you be willing to pull the latest and run the demo app (see README.md) and see if you can get HotReload to work?

https://github.com/szalapski/HotReloadIssue45519Demo

@tmat
Copy link
Member

tmat commented Jun 22, 2023

@szalapski I did. It works for me :-/

I had to remove <PackageReference Include="GeneralMills.VaultSharp.Client" Version="1.19.0" /> though since it did not restore.

@szalapski
Copy link

szalapski commented Jun 22, 2023

I had to remove <PackageReference Include="GeneralMills.VaultSharp.Client" Version="1.19.0" /> though since it did not

Thanks, I just removed that package reference as well and pushed.

@szalapski I did. It works for me :-/

Hmm, I was afraid of that. I'm going to retry. I deleted my local repo and run exactly as follows

  • git clone https://github.com/szalapski/HotReloadIssue45519Demo
  • cd .\HotReloadIssue45519Demo\
  • dotnet watch --project ./TradeCars/Server

I got a lot of irrelevant info output, but after I edit Index.razor and save it, I get:

dotnet watch ⌚ File changed: .\TradeCars\Client\Pages\Index.razor.
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
      Request starting HTTP/2 POST https://localhost:5008/_framework/blazor-hotreload application/json 2
dotnet watch ⌚ No hot reload changes to apply.
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished HTTP/2 POST https://localhost:5008/_framework/blazor-hotreload application/json 2 - 2

I have .NET SDK 7.0.302 running on Windows 10. @tmat What could be different in your run? What output do you see?

@ghost ghost locked as resolved and limited conversation to collaborators Jul 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants