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
34.89k stars 9.85k forks source link

[Hot Reload] Source Generator Based Error Breaks Hot Reload #36825

Closed TanayParikh closed 2 years ago

TanayParikh commented 2 years ago

https://user-images.githubusercontent.com/14852843/134277357-c850c2ab-e02f-41f9-8eaa-d7926c670b96.mov

Repro:

Start with:

<input type="text" @bind-value="@SomethingWithoutASetter" placeholder="Title">

@code {
    public string SomethingWithoutASetter { get; } = string.Empty;
}

This doesn't give any error in VSCode, but it does give the source generator error:

/Users/tanay/dev/NoteTakingSample2/Microsoft.NET.Sdk.Razor.SourceGenerators/Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator/Pages_Card_razor.g.cs(250,136): error CS0200: Property or indexer 'Card.SomethingWithoutASetter' cannot be assigned to -- it is read only [/Users/tanay/dev/NoteTakingSample2/NoteTakingSample2.csproj]

However, even after removing the offending <input> tag entirely the source generator error persists (perhaps it should've been marked as a rude edit?). Must exit dotnet watch and restart to resume functionality.

TanayParikh commented 2 years ago

This doesn't give any error in VSCode, but it does give the source generator error:

/Users/tanay/dev/NoteTakingSample2/Microsoft.NET.Sdk.Razor.SourceGenerators/Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator/Pages_Card_razor.g.cs(250,136): error CS0200: Property or indexer 'Card.SomethingWithoutASetter' cannot be assigned to -- it is read only [/Users/tanay/dev/NoteTakingSample2/NoteTakingSample2.csproj]

Is this a known issue @NTaylorMullen or should I create a separate issue for the missing VSCode diagnostic?

NTaylorMullen commented 2 years ago

Not a known issue that I know of at least. Sounds like SourceGenerator errors aren't being propagated to the IDE in VSCode? Probably an omnisharp-roslyn thing if I had to guess

pranavkm commented 2 years ago

That's a regular compiler error, no? Does it appear when you do dotnet build?

TanayParikh commented 2 years ago

Not a known issue that I know of at least. Sounds like SourceGenerator errors aren't being propagated to the IDE in VSCode? Probably an omnisharp-roslyn thing if I had to guess

image

Error shows up in the error pane (under generated C# file), which explains why the squiggle isn't there for the .razor file. Do we need to remap?

pranavkm commented 2 years ago

@chsienki this looks like a source generator caching bug. We were able to workaround this by configuring the disable-generator-cache feature. @TanayParikh was using an RTM labeled installer / SDK, so it's possible that the versions there might by out-of-date.

Do you happen to know if there was any recent changes made here that might have regressed this?

pranavkm commented 2 years ago

FYI @jaredpar since @chsienki is OOF

jaredpar commented 2 years ago

We were able to workaround this by configuring the disable-generator-cache feature. @TanayParikh was using an RTM labeled installer / SDK, so it's possible that the versions there might by out-of-date.

This definitively means you're using a pre-RC1 version of the compiler. As a part of fixing the caching bug we ripped that option out of the compiler entirely. It was flipped into an opt-in option. Hence if that is fixing the behavior then you're using a compiler that does not have the fix.

mkArtakMSFT commented 2 years ago

Closing as this is now fixed plus it's (was) a compiler issue