Skip to content
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

AD0001: Analyzer 'Microsoft.CodeAnalysis.CodeStyle.CSharpFormattingAnalyzer' threw an exception of type 'System.TypeLoadException' #7312

Closed
BatanGaming opened this issue May 15, 2024 · 8 comments

Comments

@BatanGaming
Copy link

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

Version: SDK 8.0.300

Describe the bug

Rider gives error in each file
AD0001: Analyzer 'Microsoft.CodeAnalysis.CodeStyle.CSharpFormattingAnalyzer' threw an exception of type 'System.TypeLoadException' with message 'Could not load type 'Microsoft.CodeAnalysis.SyntaxList' from assembly 'Microsoft.CodeAnalysis, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.'.

Also IDE0100 gives false positive result on == false, like this
where ep.Archived == false
Which was not the case before on SDK version 8.0.204

JensDll added a commit to JensDll/MinimalApiBuilder that referenced this issue May 21, 2024
@sharwell
Copy link
Member

sharwell commented May 22, 2024

Microsoft.CodeAnalysis, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35

This assembly isn't part of or referenced by the SDK 8.0.300. I have no idea how this message could be appearing.

@BatanGaming
Copy link
Author

Microsoft.CodeAnalysis, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35

This assembly isn't part of or referenced by the SDK 8.0.300. I have no idea how this message could be appearing.
Here's the screenshot if it helps. Different files can give different error message...

Screenshot 2024-05-22 at 15 23 46

@sharwell
Copy link
Member

sharwell commented May 22, 2024

Version 42.42.42.42 is a designator for an assembly which is not part of an official build or distribution. Something has provided and loaded an assembly which isn't part of the SDK or Visual Studio; we'd need to locate the specific assembly that is being loaded to understand why it exists on the machine in question.

@n0099
Copy link

n0099 commented May 23, 2024

we'd need to locate the specific assembly that is being loaded to understand why it exists on the machine in question.

I'm encountering this exception with ReSharper cli which can run Roslyn analyzer while inspecting: https://github.com/n0099/open-tbm/actions/runs/9141114339/job/25135170215

Warning: "[AD0001] Analyzer 'Microsoft.CodeAnalysis.CodeStyle.CSharpFormattingAnalyzer' threw an exception of type 'System.TypeLoadException' with message 'Could not load type 'Microsoft.CodeAnalysis.SyntaxList' from assembly 'Microsoft.CodeAnalysis, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.'.
Exception occurred with following context:
Compilation: tbm.Crawler
SyntaxTree: /home/runner/work/open-tbm/open-tbm/c#/crawler/Program.cs

System.TypeLoadException: Could not load type 'Microsoft.CodeAnalysis.SyntaxList' from assembly 'Microsoft.CodeAnalysis, Version=42.42.42.42, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at Microsoft.CodeAnalysis.CSharp.Extensions.MemberDeclarationSyntaxExtensions.GetAttributes(MemberDeclarationSyntax member)
   at Microsoft.CodeAnalysis.CSharp.Formatting.FormattingHelpers.GetFirstAndLastMemberDeclarationTokensAfterAttributes(MemberDeclarationSyntax node)
   at Microsoft.CodeAnalysis.CSharp.Formatting.SuppressFormattingRule.AddSpecificNodesSuppressOperations(List`1 list, SyntaxNode node)
   at Microsoft.CodeAnalysis.Formatting.Rules.NextSuppressOperationAction.Invoke()
   at Microsoft.CodeAnalysis.CSharp.Formatting.ElasticTriviaFormattingRule.AddSuppressOperations(List`1 list, SyntaxNode node, NextSuppressOperationAction& nextOperation)
   at Microsoft.CodeAnalysis.Formatting.Rules.NextSuppressOperationAction.Invoke()
   at Microsoft.CodeAnalysis.CSharp.Formatting.SpacingFormattingRule.AddSuppressOperations(List`1 list, SyntaxNode node, NextSuppressOperationAction& nextOperation)
   at Microsoft.CodeAnalysis.Formatting.Rules.NextSuppressOperationAction.Invoke()
   at Microsoft.CodeAnalysis.CSharp.Formatting.WrappingFormattingRule.AddSuppressOperations(List`1 list, SyntaxNode node, NextSuppressOperationAction& nextOperation)
   at Microsoft.CodeAnalysis.Formatting.ChainedFormattingRules.AddSuppressOperations(List`1 list, SyntaxNode currentNode)
   at Microsoft.CodeAnalysis.Formatting.AbstractFormatEngine.AddOperations[T](SegmentedList`1 operations, List`1 scratch, SyntaxNode node, Action`2 addOperations)
   at Microsoft.CodeAnalysis.Formatting.AbstractFormatEngine.CreateNodeOperations(CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Formatting.AbstractFormatEngine.Format(CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.Formatting.AbstractSyntaxFormatting.GetFormattingResult(SyntaxNode node, IEnumerable`1 spans, SyntaxFormattingOptions options, IEnumerable`1 rules, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CodeStyle.FormattingAnalyzerHelper.AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context, ISyntaxFormatting formattingProvider, DiagnosticDescriptor descriptor, SyntaxFormattingOptions options)
   at Microsoft.CodeAnalysis.CodeStyle.AbstractFormattingAnalyzer.<>c__DisplayClass4_0.<InitializeWorker>b__1(SyntaxTreeAnalysisContext treeContext)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken) in Z:\BuildAgent\work\3b7ce003563d6f8f\src\Compilers\Core\Portable\DiagnosticAnalyzer\AnalyzerExecutor.cs:line 1185
-----

Suppress the following diagnostics to disable this analyzer: IDE0055" on /home/runner/work/open-tbm/open-tbm/c#/crawler/Program.cs

This only happens to this muno92/resharper_inspectcode action, not in Visual Studio or msbuild cli.
Analyzer packages being used: https://github.com/n0099/open-tbm/blob/724585d238a3808ba6e85fbac7f24d701e693634/c%23/shared/tbm.Shared.csproj#L18-L27

@sharwell
Copy link
Member

Since there is no way to link this issue to a product we create or distribute, I'm going to resolve this issue as Won't Fix. The publisher of the unofficial compiler package would be responsible for addressing this.

@sharwell sharwell closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
@herebebeasties
Copy link

See dotnet/roslyn#73508 which looks closely related.

@JensDll
Copy link

JensDll commented May 28, 2024

I have a reproduction of this particular error for anyone interested. See https://github.com/JensDll/LoadError and the latest workflow runs. As far as I can tell, this error is caused by an incompatibility between some built-in analyzers of SDK 8.0.300 and an older version of Microsoft.CodeAnalysis.dll. So anyone fixing this must make sure the newer assemblies are findable when loading the latest analyzers.

@dxynnez
Copy link

dxynnez commented May 29, 2024

This is likely an issue at the jetbrain side, see - https://youtrack.jetbrains.com/issue/RIDER-111443/Roslyn-analyzer-failure-with-.NET-8-SDK-preview-8.0.300-preview.24203.14-and-8.0.300-release

I downgraded the SDK to 8.0.2xx to temporarily work around the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants