Skip to content

RazorSourceGenerator fails with net10.0 Preview 3 #61439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
richardhauer opened this issue Apr 11, 2025 · 6 comments
Closed
1 task done

RazorSourceGenerator fails with net10.0 Preview 3 #61439

richardhauer opened this issue Apr 11, 2025 · 6 comments
Labels
needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically

Comments

@richardhauer
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have just updated SDK and packages to the new Preview 3 versions and I can no longer compile a Razor Class Library. Possibly also other projects that depend on it, but I'm blocked so far at the RCL.

I get two errors that appear to be directly related to the net10 build:

warning CS8032: An instance of analyzer Microsoft.CodeAnalysis.Razor.Compiler.Analyzers.ComponentParameterNullableWarningSuppressor cannot be created from C:\Program Files\dotnet\sdk\10.0.100-preview.3.25201.16\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.CodeAnalysis.Razor.Compiler.dll : Method 'get_SupportedSuppressions' in type 'Microsoft.CodeAnalysis.Razor.Compiler.Analyzers.ComponentParameterNullableWarningSuppressor' from assembly 'Microsoft.CodeAnalysis.Razor.Compiler, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation..

and

warning CS8784: Generator 'RazorSourceGenerator' failed to initialize. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'MissingMethodException' with message 'Method not found: 'Microsoft.CodeAnalysis.IncrementalValueProvider`1<System.Collections.Immutable.ImmutableArray`1<!!0>> Microsoft.CodeAnalysis.IncrementalValueProviderExtensions.Collect(Microsoft.CodeAnalysis.IncrementalValuesProvider`1<!!0>)'.'.

I can't find a workaround for now and there does not appear to be any way to update the RazorSourceGenerator from 9.0.0.0 to anything higher using nuGet or VS update.

We can repro this error using just the template RCL with no code changes.
Image

The screen shot shows that, while the library compiles with the warnings, the types that should have been included from the Razor files are missing from the output, as you'd expect from these warnings.

Expected Behavior

Project should build as normal. RazorSourceGenerator needs an update if there are breaking changes in dependent libraries.

While the RCL library does build, without the RazorSourceGenerator the Razor types inside the library are not included in the output, so it is not possible to refer to these in other projects.

Steps To Reproduce

My project hierarchy is big and convoluted.

I created a new, entirely blank Razor Class Library from the Visual Studio templates, based on Net10 Preview. Did nothing at all to the code.

Build. Got the same warnings from the compiler.
So, this is pretty easily reproducible.

Attempting to reference Razor types or namespaces from other libraries causes build failures (obviously).

Exceptions (if any)

No response

.NET Version

10.0.100-preview.3.25201.16

Anything else?

I am using Visual Studio Enterprise 17.14.0 Preview 2.0
Windows 11 Enterprise 24H2 (26100.3624)

This is my installed workload list:

Installed Workload Id      Manifest Version                                 Installation Source
------------------------------------------------------------------------------------------------------------------------------------------
android                    36.0.0-preview.3.22/10.0.100-preview.3           SDK 10.0.100-preview.3, VS 17.14.35906.104, VS 17.12.35707.178
aspire                     8.2.2/8.0.100                                    SDK 10.0.100-preview.3, VS 17.12.35707.178
ios                        18.2.10695-net10-p3/10.0.100-preview.3           SDK 10.0.100-preview.3, VS 17.14.35906.104, VS 17.12.35707.178
maccatalyst                18.2.10695-net10-p3/10.0.100-preview.3           SDK 10.0.100-preview.3, VS 17.14.35906.104, VS 17.12.35707.178
macos                      15.2.10695-net10-p3/10.0.100-preview.3           SDK 10.0.100-preview.3, VS 17.14.35906.104
maui                       10.0.0-preview.3.25208.1/10.0.100-preview.3      SDK 10.0.100-preview.3
maui-windows               10.0.0-preview.3.25208.1/10.0.100-preview.3      SDK 10.0.100-preview.3, VS 17.14.35906.104, VS 17.12.35707.178
wasm-tools                 10.0.0-preview.3.25171.5/10.0.100-preview.3      SDK 10.0.100-preview.3, VS 17.14.35906.104, VS 17.12.35707.178
wasm-tools-net6            10.0.0-preview.3.25171.5/10.0.100-preview.3      SDK 10.0.100-preview.3, VS 17.14.35906.104
wasm-tools-net8            10.0.0-preview.3.25171.5/10.0.100-preview.3      SDK 10.0.100-preview.3, VS 17.14.35906.104

This is my SDK list

9.0.102 [C:\Program Files\dotnet\sdk]
9.0.104 [C:\Program Files\dotnet\sdk]
9.0.200 [C:\Program Files\dotnet\sdk]
10.0.100-preview.2.25164.34 [C:\Program Files\dotnet\sdk]
10.0.100-preview.3.25201.16 [C:\Program Files\dotnet\sdk]

Output from dotnet --info

.NET SDK:
 Version:           10.0.100-preview.3.25201.16
 Commit:            9dee3cf508
 Workload version:  10.0.100-preview.3.25208.1
 MSBuild version:   17.14.0-preview-25177-05+903614e16

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.26100
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.100-preview.3.25201.16\

.NET workloads installed:
 [android]
   Installation Source: SDK 10.0.100-preview.3, VS 17.14.35906.104, VS 17.12.35707.178
   Manifest Version:    36.0.0-preview.3.22/10.0.100-preview.3
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\10.0.100-preview.3\microsoft.net.sdk.android\36.0.0-preview.3.22\WorkloadManifest.json
   Install Type:              Msi

 [aspire]
   Installation Source: SDK 10.0.100-preview.3, VS 17.12.35707.178
   Manifest Version:    8.2.2/8.0.100
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
   Install Type:              Msi

 [ios]
   Installation Source: SDK 10.0.100-preview.3, VS 17.14.35906.104, VS 17.12.35707.178
   Manifest Version:    18.2.10695-net10-p3/10.0.100-preview.3
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\10.0.100-preview.3\microsoft.net.sdk.ios\18.2.10695-net10-p3\WorkloadManifest.json
   Install Type:              Msi

 [maccatalyst]
   Installation Source: SDK 10.0.100-preview.3, VS 17.14.35906.104, VS 17.12.35707.178
   Manifest Version:    18.2.10695-net10-p3/10.0.100-preview.3
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\10.0.100-preview.3\microsoft.net.sdk.maccatalyst\18.2.10695-net10-p3\WorkloadManifest.json
   Install Type:              Msi

 [macos]
   Installation Source: SDK 10.0.100-preview.3, VS 17.14.35906.104
   Manifest Version:    15.2.10695-net10-p3/10.0.100-preview.3
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\10.0.100-preview.3\microsoft.net.sdk.macos\15.2.10695-net10-p3\WorkloadManifest.json
   Install Type:              Msi

 [maui]
   Installation Source: SDK 10.0.100-preview.3
   Manifest Version:    10.0.0-preview.3.25208.1/10.0.100-preview.3
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\10.0.100-preview.3\microsoft.net.sdk.maui\10.0.0-preview.3.25208.1\WorkloadManifest.json
   Install Type:              Msi

 [maui-windows]
   Installation Source: SDK 10.0.100-preview.3, VS 17.14.35906.104, VS 17.12.35707.178
   Manifest Version:    10.0.0-preview.3.25208.1/10.0.100-preview.3
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\10.0.100-preview.3\microsoft.net.sdk.maui\10.0.0-preview.3.25208.1\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools]
   Installation Source: SDK 10.0.100-preview.3, VS 17.14.35906.104, VS 17.12.35707.178
   Manifest Version:    10.0.0-preview.3.25171.5/10.0.100-preview.3
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\10.0.100-preview.3\microsoft.net.workload.mono.toolchain.current\10.0.0-preview.3.25171.5\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools-net6]
   Installation Source: SDK 10.0.100-preview.3, VS 17.14.35906.104
   Manifest Version:    10.0.0-preview.3.25171.5/10.0.100-preview.3
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\10.0.100-preview.3\microsoft.net.workload.mono.toolchain.net6\10.0.0-preview.3.25171.5\WorkloadManifest.json
   Install Type:              Msi

 [wasm-tools-net8]
   Installation Source: SDK 10.0.100-preview.3, VS 17.14.35906.104
   Manifest Version:    10.0.0-preview.3.25171.5/10.0.100-preview.3
   Manifest Path:       C:\Program Files\dotnet\sdk-manifests\10.0.100-preview.3\microsoft.net.workload.mono.toolchain.net8\10.0.0-preview.3.25171.5\WorkloadManifest.json
   Install Type:              Msi

Configured to use workload sets when installing new manifests.

Host:
  Version:      10.0.0-preview.3.25171.5
  Architecture: x64
  Commit:       0a33e18a0b

.NET SDKs installed:
  9.0.102 [C:\Program Files\dotnet\sdk]
  9.0.104 [C:\Program Files\dotnet\sdk]
  9.0.200 [C:\Program Files\dotnet\sdk]
  10.0.100-preview.2.25164.34 [C:\Program Files\dotnet\sdk]
  10.0.100-preview.3.25201.16 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.0-preview.2.25164.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.0-preview.3.25172.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.0-preview.2.25163.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.0-preview.3.25171.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 10.0.0-preview.2.25163.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 10.0.0-preview.3.25174.1 [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:
  Not found

Not sure what else might be of value. The RCL project is pretty standard - the Project SDK is Microsoft.NET.Sdk.Razor and the TargetFramework is set to net10.0 with Nullable also set to enable

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Apr 11, 2025
@richardhauer
Copy link
Author

For anyone arriving here with the same error, this is a regression from the Preview 2 release.
Install the Preview 2 SDK and create a file called global.json in the root of your solution.
Use (at least) the following in global.json

{
  "sdk": {
    "version": "10.0.100-preview.2.25164.34",
    "allowPrerelease": true,
    "rollForward": "disable"
  }
}

This will tell dotnet to use the Preview 2 SDK, even though all the libraries are still Preview 3 spec.

@martincostello
Copy link
Member

Does it build correctly with preview 3 using the CLI and it's just a Visual Studio issue, or is it broken with both?

@richardhauer
Copy link
Author

richardhauer commented Apr 11, 2025

As with VS, dotnet build results in warnings on the RCL build, but that succeeds. Trying to dotnet build anything that depends on the RCL fails, because the types exposed by the Razor files are not in the output assembly.

"Broken with both" I would say.

(I'm testing against my solution and not against the default VS templates, but I've no reason to expect the behaviour will be different).

This all works fine in P2, so the issue is a regression, or more likely a breaking change in P3 that is not accounted for in the RazorSourceGenerator.

@martincostello
Copy link
Member

This issue might be one for dotnet/razor rather than here. Someone on the aspnetcore team can move it if that's the case.

@dotnetnoobie
Copy link

dotnetnoobie commented Apr 13, 2025

@richardhauer the way I solved this issue was to grab the nightly build for the preview 4 SDK (10.0.100-preview.4.25211.22)
https://github.com/dotnet/sdk/blob/main/documentation/package-table.md

This meant I started to get this error
Unable to attach to CoreCLR. Signature validation failed for a .NET Runtime Debugger library because the file is unsigned.

Which I solved by setting the VSDebugger_ValidateDotnetDebugLibSignatures environment variable
https://github.com/dotnet/runtime/blob/main/docs/workflow/debugging/coreclr/debugging-runtime.md#resolving-signature-validation-errors-in-visual-studio

I created a .bat file in the root folder of my BlazorApp solution and added these 2 lines, I use this to start VS2022 preview, which prevented the above error when running the project

set VSDebugger_ValidateDotnetDebugLibSignatures=0
"C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\devenv.exe"

You also need to add a NuGet.Config file to the root of your solution

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <clear />
        <add key="dotnet10" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet10/nuget/v3/index.json" />
        <add key="NuGet.org" value="https://api.nuget.org/v3/index.json" />
    </packageSources>
</configuration>

@richardhauer
Copy link
Author

Seems that the latest VS Preview release fixes this issue, according to notes on dotnet/razor#11735 so I will close this out now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically
Projects
None yet
Development

No branches or pull requests

3 participants