Weird errors problem with dotnet watch with blazor/wasm.

Tendenz Noord 6 Reputation points
2022-02-28T10:45:49.527+00:00

I have a really annoying problem with dotnet watch and blazor/wasm. I have a solution in which I have multplie projects, for example an API, a blazor/wasm project and some common classlibraries.
I start the API part with CTRL+F5, and I start the Blazor part from the Windows terminal with dotnet watch (because I want to use hot reload).
Now the project starts up fine and everything works. But when I change something in one of the blazor files, the blazor app displays LOTS of errors about not being able to find stuff, both in the browser window as in the dotnet watch terminal.
This even happens when I do not make any change but simply do Ctrl+S in Visual Studio. If I then close the Blazor app, and restart the dotnet watch command, everything builds fine, until some file's modification date is updated.

If I git clone the project on another location on the same PC, everything works fine, until a (few) day(s) later.
If I completely delete the original project location on the PC and re-clone the project, the problem persists. As if it remembers the project location.
Now I can only fix this temporarily by changing the project working directory location every other day...

What on earth can this be?

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,594 questions
{count} vote

4 answers

Sort by: Most helpful
  1. Isak Savo 20 Reputation points
    2023-02-14T16:31:44.96+00:00

    I had this (or something similar) happen to me today when I refactored my blazor single project web app into multiple projects inside the same solution. This is on the latest .NET 7, on a blazor server app.

    Whenever I modified any file that would normally work with hot reload, dotnet watch just barfed tons of (invalid) errors and stopped working. Had to ctrl+r to rebuild and then F5 in the browser to keep working. Super annoying.

    Going back to a branch before the refactoring made dotnet watch work again.

    Anyway, for me it was because one of my csproj files had a bunch of <AdditionalFiles .../> in it, causing dotnet watch to report them as duplicates when running with --verbose:

    dotnet watch 🚀 Started
    dotnet watch ⌚ MSBuildWorkspace warning: [Warning] Duplicate source file 'C:\github\MyApp\SomeFile.razor' in project 'C:\github\MyApp\SomeProject.csproj'
    ... etc 
    
    

    Removing the entire <ItemGroup> with all those AdditionalFiles entries from the .csproj file solved the problem for me.

    4 people found this answer helpful.

  2. Tendenz Noord 6 Reputation points
    2022-02-28T11:32:54.257+00:00

    What bug? That's the thing, if i restart the dotnet watch command it works again.. there's no bug.
    I've seen this mentioned some 14 months ago :https://github.com/dotnet/aspnetcore/issues/28541
    No solution there however.


  3. Tendenz Noord 6 Reputation points
    2022-02-28T13:38:22.953+00:00

    Oke, but what if:

    • I stop everything.
    • I clean everything (and even remove all bin/ obj/ .vs folders)
    • I build the whole solution in VS --> no build errors!
    • I start dotnet watch again

    and I still have the problem once I add a space or something to a file. Even if I run 'dotnet build' from the blazor/wasm project it reports no errors.
    Is there a workaround for this aside from moving the whole project to another location which seems to help shortly?


  4. Tendenz Noord 6 Reputation points
    2022-03-01T10:00:19.023+00:00

    I'll do that, i'll issue it via the Send Feedback button.
    In the meantime I see this same problem was already an issue in the .ENT 5.0.1 beta time: https://github.com/dotnet/aspnetcore/issues/28541


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.