roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:\ Users\sacsharm\.nuget\packages\system.text.json\6.0.0\analyzers\dotnet\roslyn3.11\cs\System.Text.Json.SourceGeneration.dll

Open ssachin872 opened this issue 1 year ago • 3 comments

Brief description: Getting this error while adding "Microsoft.Identity.ServiceEssentials.SDK" this package in project Describe your code style rule here.

Languages applicable:

Is your analyzer C# only? VB Only? Or Both?

Code example that the analyzer should report:

A small code snippet that describes a case that the analyzer should report.

Additional information:

Any more additional information you would like to add.

Documentation requirements:

When this analyzer is implemented, it must be documented by following the steps at Documentation for IDE CodeStyle analyzers.

ssachin872 avatar Jul 03 '24 07:07 ssachin872

CSC : error CS8032: An instance of analyzer System.Text.Json.SourceGeneration.JsonSourceGenerator cannot be created from C:
Users\sacsharm.nuget\packages\system.text.json\6.0.0\analyzers\dotnet\roslyn3.11\cs\System.Text.Json.SourceGeneration.dll : C ould not load file or assembly 'Microsoft.CodeAnalysis, Version=3.11.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. [C:\SCOM\SystemCenter-SCOMMIService\src\Service\RestApi
RestApi.Controllers\Microsoft.Scom.RestApi.Controllers.csproj]

Complete error is this

ssachin872 avatar Jul 03 '24 07:07 ssachin872

This isn't like a Roslyn issue; @ssachin872 can you do a command line build passing /bl to msbuild or dotnet build (for example msbuild /bl) and share the resulting msbuild.binlog file that is created?

jasonmalinowski avatar Jul 09 '24 22:07 jasonmalinowski

@ssachin872 Are you still able to reproduce this and share a binlog?

jasonmalinowski avatar Aug 26 '24 20:08 jasonmalinowski

@jasonmalinowski It seems that this is the same (or at least very similar) problem I've reported in reactiveui/ReactiveUI.SourceGenerators#51.

EDIT: Here is a sample repository, but it seems that not everybody gets this error?

Here's a copy of my relevant comment of the issue:

This is the output of my dotnet --info:

PS C:\temp\TestReactiveUiSourceGenBug2> dotnet --info
.NET SDK:
 Version:           8.0.401
 Commit:            811edcc344
 Workload version:  8.0.400-manifests.f51a3a6b
 MSBuild version:   17.11.4+37eb419ad

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22631
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.401\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
  Version:      8.0.8
  Architecture: x64
  Commit:       08338fcaa5

.NET SDKs installed:
  3.1.426 [C:\Program Files\dotnet\sdk]
  6.0.425 [C:\Program Files\dotnet\sdk]
  8.0.400 [C:\Program Files\dotnet\sdk]
  8.0.401 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.8 [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\TestReactiveUiSourceGenBug2\global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

And this is the full build output:

PS C:\temp\TestReactiveUiSourceGenBug2> dotnet build
  Determining projects to restore...
  Restored C:\temp\TestReactiveUiSourceGenBug2\TestReactiveUiSourceGenBug2.csproj (in 590 ms).
CSC : warning CS8032: An instance of analyzer ReactiveUI.SourceGenerators.AsyncVoidReturningReactiveCommandMethodAnalyzer cannot be created from C:\Users\Mark Junker\.nuget\packages\reactiveui.sourcegenerators\1.1.31\analyzers\dotnet\cs\ReactiveUI.SourceGenerators.dll : Exception has been thrown by the target of an invocation.. [C:\temp\TestReactiveUiSourceGenBug2\TestReactiveUiSourceGenBug2.csproj]
CSC : warning AD0001: Analyzer 'ReactiveUI.SourceGenerators.CodeAnalyzers.PropertyToReactiveFieldAnalyzer' threw an exception of type 'System.TypeInitializationException' with message 'The type initializer for 'ReactiveUI.SourceGenerators.Diagnostics.DiagnosticDescriptors' threw an exception.'. [C:\temp\TestReactiveUiSourceGenBug2\TestReactiveUiSourceGenBug2.csproj]
CSC : warning AD0001: Analyzer 'ReactiveUI.SourceGenerators.UnsupportedCSharpLanguageVersionAnalyzer' threw an exception of type 'System.TypeInitializationException' with message 'The type initializer for 'ReactiveUI.SourceGenerators.Diagnostics.DiagnosticDescriptors' threw an exception.'. [C:\temp\TestReactiveUiSourceGenBug2\TestReactiveUiSourceGenBug2.csproj]
  TestReactiveUiSourceGenBug2 -> C:\temp\TestReactiveUiSourceGenBug2\bin\Debug\net8.0\TestReactiveUiSourceGenBug2.dll

Build succeeded.

CSC : warning CS8032: An instance of analyzer ReactiveUI.SourceGenerators.AsyncVoidReturningReactiveCommandMethodAnalyzer cannot be created from C:\Users\Mark Junker\.nuget\packages\reactiveui.sourcegenerators\1.1.31\analyzers\dotnet\cs\ReactiveUI.SourceGenerators.dll : Exception has been thrown by the target of an invocation.. [C:\temp\TestReactiveUiSourceGenBug2\TestReactiveUiSourceGenBug2.csproj]
CSC : warning AD0001: Analyzer 'ReactiveUI.SourceGenerators.CodeAnalyzers.PropertyToReactiveFieldAnalyzer' threw an exception of type 'System.TypeInitializationException' with message 'The type initializer for 'ReactiveUI.SourceGenerators.Diagnostics.DiagnosticDescriptors' threw an exception.'. [C:\temp\TestReactiveUiSourceGenBug2\TestReactiveUiSourceGenBug2.csproj]
CSC : warning AD0001: Analyzer 'ReactiveUI.SourceGenerators.UnsupportedCSharpLanguageVersionAnalyzer' threw an exception of type 'System.TypeInitializationException' with message 'The type initializer for 'ReactiveUI.SourceGenerators.Diagnostics.DiagnosticDescriptors' threw an exception.'. [C:\temp\TestReactiveUiSourceGenBug2\TestReactiveUiSourceGenBug2.csproj]
    3 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.96

I'll also attach a build log (both text and binary). The zip file contains the binary log. build.log msbuild.zip

fubar-coder avatar Sep 20 '24 16:09 fubar-coder

@chsienki @jaredpar Does the compiler report inner exceptions for exceptions that get thrown from generators/analyzers?

jasonmalinowski avatar Sep 20 '24 20:09 jasonmalinowski

@fubar-coder I see you filed the bug on ReactiveUI and I commented there too: this is a bug in their package and they'll need to fix it.

jasonmalinowski avatar Sep 20 '24 21:09 jasonmalinowski

@jasonmalinowski Just answering your question about the inner exception: Yes, the compiler reports it, as you can see in the binary log:

grafik

But I don't understand why it cannot find the Microsoft.CodeAnalysis.Workspaces assembly, when the culprit might be the reference to Microsoft.CodeAnalysis.CSharp.Workspaces?

fubar-coder avatar Sep 20 '24 22:09 fubar-coder

But I don't understand why it cannot find the Microsoft.CodeAnalysis.Workspaces assembly, when the culprit might be the reference to Microsoft.CodeAnalysis.CSharp.Workspaces?

Microsoft.CodeAnalysis.CSharp.Workspaces will also pull a dependency in to Microsoft.CodeAnalysis.Workspaces due to NuGet dependencies; as long as a load happens for something from that assembly first, then Bad Things will happen.

jasonmalinowski avatar Sep 20 '24 22:09 jasonmalinowski

@fubar-coder Yeah it reports it in the binlog, I'm not sure why we wouldn't report it to the console though too...

jasonmalinowski avatar Sep 20 '24 22:09 jasonmalinowski

Yeah it reports it in the binlog, I'm not sure why we wouldn't report it to the console though too...

It is reported to the console but the layer which maps console output to msbuild errors doesn't account for all the cases that exceptions produce.

jaredpar avatar Sep 20 '24 22:09 jaredpar

Closing this as without further logs from @ssachin872 I won't be able to anything more here.

jasonmalinowski avatar Sep 27 '24 23:09 jasonmalinowski