dotnet / dotnet/sdk

Cannot get hot reload and browser link to work in some projects

Open
#51,237 9 comments 0 reactions 0 assignees View on GitHub
Area-Watch
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

If I create a new Blazor project in VisualStudio 2022 then hot reload and browser link work.

However, they stopped working in my actual project -- which started off life as the same template.

If I set a breakpoint and edit code then I get a message:

> The source file has change. It no longer matches the version of the file used to build the application being debugged.

and I have to stop and recompile --- like ASPX.

If I start a new Blazor app in Visual Studio, then hot reload works. So it must be something in my project, not the environment.

I see that somehow in the template project (but not in my project) the scripts
```

```
are somehow magically being added to the HTML source of every page and the Browser Link Dashboad in Visual Studio shows a connection.

I tried copying these into my App.razor but that made no difference --- still no conneciton in the Browser Link Dashboard.

My launch profiles are identical:
```
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",
"applicationUrl": "https://localhost:5202;http://localhost:5292",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
```
In both cases my `Program.cs` has
```
builder.Services
.AddRazorComponents()
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents();
```
and `app.UseWebAssemblyDebugging();` and both `InteractiveServer` and `InteractiveAuto` pages work.

Same result if I run from the command line instead of from Visual Studio:
```
dotnet watch run --project MyProject\MyProject.csproj --launch-profile https
```
Any ideas what to do?

### Expected Behavior

_No response_

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

_No response_

### Anything else?

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.