Skip to content

fix(generator): keep the analyzers loadable in Visual Studio - #2309

Merged
ChrisPulman merged 1 commit into
mainfrom
fix/analyzer-system-memory-binding
Aug 18, 2026
Merged

ChrisPulman merged 1 commit into
mainfrom
fix/analyzer-system-memory-binding

Conversation

@glennawatson

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix.

What is the new behavior?

The shipped generator, analyzers and code fixes load in Visual Studio again.

  • The Roslyn component projects no longer reference SourceLink. It pulls Microsoft.Build.Tasks.Git -> System.IO.Hashing, which floors System.Memory at 4.6.3 for the whole restore graph. Nothing else in those projects raised it, so removing SourceLink drops the compile-time reference back to assembly version 4.0.1.2 - the version the .NET Framework compiler host binds.
  • PackagedAnalyzerReferenceTests guards the reference set. It reads each shipped assembly's metadata and fails on anything the compiler host cannot supply: a reference must be netstandard, a Microsoft.CodeAnalysis* at the version refit.props declares, or a listed facade at its exact version.
    • A companion test asserts all three assemblies were built, so the check cannot pass vacuously. That needed a build-only ProjectReference to Refit.CodeFixes.Roslyn48, whose output the test project otherwise never produced.
    • AnalyzerPackagingTests moved its Refit.csproj parsing and repository walking into a shared RefitPackageLayout rather than duplicate them.

What is the current behavior?

The generator fails to load inside Visual Studio and emits no clients.

  • InterfaceStubGeneratorV2.dll and Refit.Analyzers.dll reference System.Memory, Version=4.0.2.0. Visual Studio's compiler host runs on .NET Framework and its binding redirects stop at 4.0.1.2, so loading throws FileNotFoundException and the compiler reports CS8784.
  • The analyzer hits the same wall, so the RF diagnostics never run in the IDE either.
  • A command-line build is unaffected, because the .NET compiler host resolves the facade from the shared framework whatever version is asked for - which is how a transitive bump reached a release without CI noticing.

Closes #2308

What might this PR break?

None for consumers.

  • Source stepping into the shipped analyzer assemblies is no longer source-linked. Their PDBs stay embedded.

Checklist

  • I have read the Contribute guide
  • Tests have been added or updated (for bug fixes / features)
  • Docs have been added or updated (for bug fixes / features)
  • Changes target the main branch
  • PR title follows Conventional Commits

Additional information

Verified against a real dotnet pack -c Release artifact, not just the bin folder:

assembly 15.1.0 this branch
InterfaceStubGeneratorV2.dll System.Memory, Version=4.0.2.0 4.0.1.2
Refit.Analyzers.dll System.Memory, Version=4.0.2.0 4.0.1.2
Refit.CodeFixes.dll no reference no reference

Pinning System.Memory while keeping SourceLink is not an option: System.IO.Hashing 10.0.11 requires >= 4.6.3, so restore fails with NU1605.

- Drop SourceLink from the Roslyn component projects. It pulls
  System.IO.Hashing, which floored System.Memory at assembly version
  4.0.2.0 for the whole restore graph.
- Visual Studio's .NET Framework compiler host binds System.Memory only up
  to 4.0.1.2, so the generator threw FileNotFoundException on load and the
  build reported CS8784 with no generated clients. Refit.Analyzers had the
  same reference, silencing every RF diagnostic there too.
- Command-line builds hid it: the .NET compiler host resolves the facade
  from the shared framework whatever version is asked for.
- Add PackagedAnalyzerReferenceTests, which reads each shipped assembly's
  metadata and fails on a reference the compiler host cannot supply.

Fixes #2308
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.91%. Comparing base (74cbb64) to head (1583766).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2309   +/-   ##
=======================================
  Coverage   99.91%   99.91%           
=======================================
  Files         192      192           
  Lines       10027    10027           
  Branches     1924     1924           
=======================================
  Hits        10018    10018           
  Partials        9        9           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ChrisPulman
ChrisPulman merged commit 05c856a into main Aug 18, 2026
18 checks passed
@ChrisPulman
ChrisPulman deleted the fix/analyzer-system-memory-binding branch August 18, 2026 06:50
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Warning CS8784 during the build in VS2022

2 participants

⌂ 换网址