Closed zhurst31 closed 3 months ago
@zhurst31 thanks for reporting this issue. I see in https://github.com/zhurst31/RazorNullableIssue/pull/1/files that this is about @inherits
directive. That was indeed fixed to be nullable enabled in https://github.com/dotnet/razor/pull/8348.
the project fails to compile
I assume you are getting just nullability warnings and you have WarningsAsErrors enabled. Otherwise, the project should compile fine.
In summary, this looks expected - @inherits
wasn't nullable-enabled previously which was a bug (as you noted - it wasn't possible to have nullable annotations inside it). Changing that is a slight breaking change but also a bug fix.
@jjonescz thanks for the insight! I was able to fix all the places we had the issue and upgraded the project successfully to 8.0.300. Will close this out.
Describe the bug
I may have missed an announcement about a breaking change so apologies in advance, but when updating to 8.0.300 and not making any code changes, my razor class library fails to build. This has to do with nullability between the razor file and the code behind.
To Reproduce
If you use the main branch here https://github.com/zhurst31/RazorNullableIssue and compile the project with the 8.0.105 SDK, it builds fine. If you simply bump the SDK in the global json to 8.0.300, the project fails to compile. You can see in this PR how I had to fix it https://github.com/zhurst31/RazorNullableIssue/pull/1/files. I had to add the nullable to the razor file.
Now in the 8.0.105 SDK, if I add the nullable to the razor file, I get a warning about
"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"
. Our project has warnings as errors turned on, so leaving the question mark in there with the 8.0.105 SDK and ignoring the warning was not an acceptable choice for us at the time.Exceptions (if any)
Upgrading to 8.0.300 seems like it adds nullable annotation support to razor files, causing a preexisting project to fail unless changes are made.
Further technical details
dotnet --info
(when pinned to 8.0.105 sdk)Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.105\
.NET workloads installed: Workload version: 8.0.100-manifests.4e5ea2d8 [aspire] Installation Source: SDK 8.0.100, VS 17.10.34916.146 Manifest Version: 8.0.0/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.0.0\WorkloadManifest.json Install Type: Msi
[ios] Installation Source: VS 17.10.34916.146 Manifest Version: 17.2.8053/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.2.8053\WorkloadManifest.json Install Type: Msi
[android] Installation Source: VS 17.10.34916.146 Manifest Version: 34.0.95/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.95\WorkloadManifest.json Install Type: Msi
[maui-windows] Installation Source: VS 17.10.34916.146 Manifest Version: 8.0.21/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.21\WorkloadManifest.json Install Type: Msi
[maccatalyst] Installation Source: VS 17.10.34916.146 Manifest Version: 17.2.8053/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.2.8053\WorkloadManifest.json Install Type: Msi
Host: Version: 8.0.5 Architecture: x64 Commit: 087e15321b
.NET SDKs installed: 7.0.409 [C:\Program Files\dotnet\sdk] 8.0.105 [C:\Program Files\dotnet\sdk] 8.0.300 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables: Not set
global.json file: C:\Temp\RazorNullableIssue\global.json
Learn more: https://aka.ms/dotnet/info
Download .NET: https://aka.ms/dotnet/download
.NET SDK: Version: 8.0.300 Commit: 326f6e68b2 Workload version: 8.0.300-manifests.4e5ea2d8 MSBuild version: 17.10.4+10fbfbf2e
Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.300\
.NET workloads installed: [ios] Installation Source: VS 17.10.34916.146 Manifest Version: 17.2.8053/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.ios\17.2.8053\WorkloadManifest.json Install Type: Msi
[android] Installation Source: VS 17.10.34916.146 Manifest Version: 34.0.95/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.android\34.0.95\WorkloadManifest.json Install Type: Msi
[aspire] Installation Source: VS 17.10.34916.146 Manifest Version: 8.0.0/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.0.0\WorkloadManifest.json Install Type: Msi
[maui-windows] Installation Source: VS 17.10.34916.146 Manifest Version: 8.0.21/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maui\8.0.21\WorkloadManifest.json Install Type: Msi
[maccatalyst] Installation Source: VS 17.10.34916.146 Manifest Version: 17.2.8053/8.0.100 Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.maccatalyst\17.2.8053\WorkloadManifest.json Install Type: Msi
Host: Version: 8.0.5 Architecture: x64 Commit: 087e15321b
.NET SDKs installed: 7.0.409 [C:\Program Files\dotnet\sdk] 8.0.105 [C:\Program Files\dotnet\sdk] 8.0.300 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.27 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables: Not set
global.json file: C:\Temp\RazorNullableIssue\global.json
Learn more: https://aka.ms/dotnet/info
Download .NET: https://aka.ms/dotnet/download