-
Notifications
You must be signed in to change notification settings - Fork 229
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
same as dotnet/aspnetcore#32733
When Nullable Reference Types are enabled (enable in the .csproj), referring to a supertype with nullable parts results in a generated .razor.g.cs which disables nullable reference types then uses one. This line:
@implements SomeGeneric<T?>
results in warning CS8669, "The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.". However, there is no way to enable the nullable annotations context for the generated code or to disable it for the .razor file, leaving you in a catch-22 situation.
I can confirm this issue is back after the latest update of the dotnet SDKs (tested on 6.0.300 and also 6.0.400-preview.22301.10).
Expected Behavior
the auto-generated code for the Blazor components (generated by Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator) should not raise the CS8669 warning.
Steps To Reproduce
Here is a repro to reproduce this issue: https://github.com/msynk/repro-blazor-nullable-generic-params
run dotnet build on a fresh code (without the auto-generated code in the obj folder) or run dotnet clean before the build command.
the warning is coming from this line:
@inherits BaseComponent<string?>Exceptions (if any)
No response
.NET Version
6.0.400-preview.22301.10
Anything else?
> dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.400-preview.22301.10
Commit: 25580ffe7a
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\6.0.400-preview.22301.10\
Host (useful for support):
Version: 6.0.6
Commit: 7cca709db2
.NET SDKs installed:
5.0.103 [C:\Program Files\dotnet\sdk]
5.0.301 [C:\Program Files\dotnet\sdk]
5.0.303 [C:\Program Files\dotnet\sdk]
5.0.409 [C:\Program Files\dotnet\sdk]
6.0.301 [C:\Program Files\dotnet\sdk]
6.0.400-preview.22301.10 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
this is an image of the output of the dotnet build command:
