[CLI] Fix loading analyzers that reference System.Composition on .NET 10 - #1831
Open
helgeu wants to merge 2 commits into
Open
[CLI] Fix loading analyzers that reference System.Composition on .NET 10#1831helgeu wants to merge 2 commits into
helgeu wants to merge 2 commits into
Conversation
The .NET 10 SDK ships analyzers and code fix providers that reference System.Composition but does not deploy System.Composition next to them. The version they were compiled against tracks the SDK patch level (for example 10.0.0.10) and is higher than the copy restored for the tool, so loading fixers failed with FileNotFoundException. Redirect System.Composition.* to the copy shipped with the tool, ignoring the requested version.
helgeu
force-pushed
the
fix/1649-system-composition-net10
branch
from
September 3, 2026 04:50
078a278 to
e331730
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
net8.0,net9.0andnet10.0Summary
roslynator analyzeandfixcrash on the first project when run on the .NET 10 SDK:Root cause
The compiler only loads diagnostic analyzers, whose attributes live in
Microsoft.CodeAnalysis, so the SDK does not deploySystem.Compositionnext to its analyzer / code-fix assemblies. Roslynator also inspects code fix providers, so reading their[ExportCodeFixProvider]/[Shared]attributes forcesSystem.Composition.AttributedModelto load. The SDK analyzers are compiled against the SDK's copy, whose assembly version tracks the SDK patch level (10.0.0.10here). Roslynator restoresSystem.Compositiontransitively through Roslyn (9.0.0), so the higher-versioned reference cannot bind and the load fails.This is the same class of problem as #1729 / #1783 (MSBuild): an assembly whose version moves independently of Roslynator's releases, so matching the version is not viable. Unlike MSBuild, there is no locator that resolves
System.Composition, and the SDK does not place it next to the analyzers, so it cannot be resolved from the SDK either.Fix
Redirect
System.Composition.*to the copy shipped with the tool, ignoring the requested version. The public surface used by the analyzer / fixer attributes (Export,Shared,ImportingConstructor, ...) is stable across versions, and Roslynator only reflects over these attributes and instantiates the types withActivator, so the deployed copy is sufficient. AnAssemblyLoadContext.Default.Resolvinghandler is registered at startup (.NET build only; the net48 build is unaffected).Verification
roslynator analyzeon a newnet10.0class library — before: crash; after: analyzers and fixers load and run (e.g. reportsCS0219).net10.0solution — before: crash on project1/9; after: all 9 projects analyze (1671 diagnostics reported).net8.0,net9.0andnet10.0.Note on tests
There is no CLI test project, and the behaviour is
AssemblyLoadContextresolution that has no natural unit-test home (the analogous #1783 shipped without one). I verified it end to end as above and am happy to add a test if you prefer.Related issue
Fixes #1649
Investigated and implemented with AI assistance (opencode).