Warning CS8032 An instance of analyzer Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator cannot be created

Viewed 6022

Using VS2019 latest version 19.9.4 and installed .NET SDK 6.0.100-preview.3 Now I cannot compile the project anymore cause it gives the error described below. If I revert to NET 5.0 it works fine. The reason for 6.0 is to use the Hot-Reload feature for Blazor. I am now in the phase to design several UI and it should save me a lot of time.

Warning CS8032 An instance of analyzer Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator cannot be created from C:\Program Files\dotnet\sdk\6.0.100-preview.3.21202.5\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=3.10.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. RPManager C:\AppCenter\RPManager\CSC 1 Active

3 Answers

This bug has to do with some versions of SDK.

Same problem occurred when building in Visual Studio 2022 17.0.6 using SDK 6.0.200. causing 'Microsoft.CodeAnalysis not to load file or assembly, and omnisharp in vscode broken on 6.0.200 with this exception.

To fix this error,either

- Update visual studio to the latest version. or

- downgrade the SDK version by adding a global.json file to specify which SDK to use.

Get the new Microsoft Visual Studio Community 2019 Preview Version 16.10.0 Preview 2.0 when using .Net 6 Preview 3.

I was using VS 17.0.6 from the LTSC 17.0 channel. Setting it to the Current or 17.2 channel and upgrading to 17.2.1 resolved the issue.

  1. From within VS, select Help > Check for Updates.
  2. Click Change update settings.
  3. Select the Current or LTSC version 17.2 update channels.
  4. Click OK.
  5. Click Update.
Related