Repository navigation
Description
See discussion under dotnet/dotnet#6573:
##[error]CSC(0,0): error CS8032: (NETCORE_ENGINEERING_TELEMETRY=Build) An instance of analyzer Microsoft.NetCore.CSharp.Analyzers.Usage.CSharpMissingShebangInFileBasedProgram cannot be created from D:\a_work\1\s\src\runtime\artifacts.packages\microsoft.codeanalysis.netanalyzers\11.0.100-preview.5.26257.113\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll : System.TypeLoadException: Could not load type 'Microsoft.NetCore.Analyzers.Usage.MissingShebangInFileBasedProgram' from assembly 'Microsoft.CodeAnalysis.NetAnalyzers, Version=11.0.100.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
It seems this is caused by the roslyn repo build using analyzers from SDK, and runtime repo build using analyzers from a newer nuget package. The latter have the new analyzer, the former don't. And the mismatch is likely caused like this:
When building roslyn repo, analyzers are loaded from the sdk:
.dotnet/sdk/11.0.100-preview.5.26227.104/Sdks/Microsoft.NET.Sdk/analyzers/
Microsoft.CodeAnalysis.NetAnalyzers.dll
Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll
When building runtime repo, it requests the CSharp analyzers
runtime/artifacts/.packages/.../11.0.100-preview.5.26257.113/analyzers/dotnet/cs/
Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll
Which depends on Microsoft.CodeAnalysis.NetAnalyzers.dll analyzer but that one is not in the same folder, so it's not handled by the compiler's consistency check and instead the already loaded one (in compiler server) is happily loaded (it also has the same assembly version, 11.0.100.0), causing that mismatch (because the old one doesn't have the base type that the new one depends on).
It really looks like a bug in runtime's config then - it should be loading the analyzers from one directory to ensure consistency. Or maybe the NetAnalyzers should be packaged differently. Or maybe the assembly version of the analyzer should be bumped.
Or I guess you could work around this by making sure both repos use different compiler server (by setting SharedCompilationId).
This is essentially a cross analyzer dependency which is an unsupported area. The fix should be to put them into the same directory.
Yes, ideally, but runtime seems to just be using NetAnalyzers nuget package, so we would need to change how that's packed on the sdk side. Also it seems to be a fairly common pattern to do what NetAnalyzers package is doing - have common analyzers in the main folder and then /cs/ and /vb/ subfolders for the C#/VB specific analyzers.
Activity
jjonescz commentedon May 18, 2026
For starters I put this workaround into VMR: dotnet/dotnet@549080b
pavelsavara commentedon May 18, 2026
I'm not sure if it's related or not, I saw
during runtime build on my local machine today. It was resolved by deleting stale
d:\runtime2\.dotnetfolder.I still have the binlog if you want it.
kg commentedon May 19, 2026
This maybe also caused dotnet/runtime#128070
akoeplinger commentedon May 19, 2026
the layout changed somewhere between version 9.0.0 and 10.0.100 of the package:
Before:

After:
According to @jjonescz Roslyn's contract is that one analyzer and its dependencies need to be in one folder.
Duplicate language-agnostic NetAnalyzers.dll into cs/ and vb/ folders (…
kg commentedon May 20, 2026
This should be fixed once #54372 flows through the VMR into dotnet/runtime, do I understand correctly?
jjonescz commentedon May 20, 2026
I think this should be already closed, it wasn't auto-closed because the PR was merged into non-main branch.
kg commentedon May 20, 2026
Sorry, what I meant is, this issue (addressed by 54372, I think) is causing breakage for some CI flows on dotnet/runtime. I'm guessing for that to be fixed, 54372 will need to flow from here into the VMR and then from the VMR into dotnet/runtime, yeah?
jjonescz commentedon May 21, 2026
What issues? I put a workaround to one VMR PR: dotnet/dotnet@549080b, perhaps it needs to be cherry-picked to other branches. Although if you can wait for this fix to flow as you say, then yeah, that's the ideal fix.
akoeplinger commentedon May 21, 2026
This one: dotnet/runtime#128070 (comment)
And yes right now the flow that needs to happen is sdk 10.0.1xx -> ... -> sdk main (via automatic inter-branch merge) -> VMR main -> runtime main.
If we need it faster (the sdk inter-branch merge can sometimes be blocked, same applies to the VMR->runtime backflow) we'd need to cherry-pick
jjonescz commentedon May 22, 2026
As a temporary workaround you could add NoWarn for CA2266 and that should disable the analyzer.
kg commentedon Jun 4, 2026
Still seeing this randomly crop up, did it just not flow yet? Is there some sort of bug that would cause it to intermittently break builds only on certain CI configurations? For example, on a Wasm-only PR, I saw the shebang error fail an OS X build but all the linux and windows lanes were fine:
https://dev.azure.com/dnceng-public/public/_build/results?buildId=1448683&view=logs&jobId=2710d842-fa61-5104-0e86-cc29dd313ead&j=2710d842-fa61-5104-0e86-cc29dd313ead&t=0b292913-8361-5e62-8106-16cdc9499d26
jjonescz commentedon Jun 4, 2026
Depends on where you mean. It didn't flow to 10.0.4xx and newer yet, stuck here it seems: #54459
MichalStrehovsky commentedon Jun 10, 2026
We are still seeing this in dotnet/runtime:
2026-06-10T06:28:45.4413270Z CSC : error CS8032: An instance of analyzer Microsoft.NetCore.CSharp.Analyzers.Usage.CSharpMissingShebangInFileBasedProgram cannot be created from /Users/runner/work/1/s/.packages/microsoft.codeanalysis.netanalyzers/11.0.100-preview.6.26302.118/analyzers/dotnet/cs/Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll : System.TypeLoadException: Could not load type 'Microsoft.NetCore.Analyzers.Usage.MissingShebangInFileBasedProgram' from assembly 'Microsoft.CodeAnalysis.NetAnalyzers, Version=11.0.100.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. [/Users/runner/work/1/s/src/tools/illink/src/ILLink.RoslynAnalyzer/ILLink.RoslynAnalyzer.csproj]
preview.6.26302.118 seems pretty recent (June 2nd build of dotnet/dotnet main). @jjonescz is that one expected to already have the fix? The workaround mentioned above dotnet/dotnet@549080b seems to have merged into dotnet/dotnet main three weeks ago.
MichalStrehovsky commentedon Jun 10, 2026
dotnet/runtime#129031 collects these on the dotnet/runtime side.
jjonescz commentedon Jun 10, 2026
No, the fix was stuck in code flow it seems; the PR #54459 carrying it merged only today.
That was a workaround for VMR builds only, that wouldn't affect runtime or any other builds just using the SDK.
akoeplinger commentedon Jun 13, 2026
11.0.100-preview.6.26312.114 has the fix now