Repository navigation
Pin System.Memory to 4.5.5 to fix VS 2022 analyzer load failure - #1612
Conversation
The analyzer was compiled against System.Memory 4.6.3 (assembly version 4.0.2.0), but VS 2022 only ships System.Memory 4.5.5 (assembly version 4.0.1.1). This caused a FileNotFoundException when loading the analyzer. Pinning to 4.5.5 matches what VS 2022 provides and is compatible with all APIs used by this codebase (ReadOnlyMemory<char>, ReadOnlySpan<char>, AsMemory(), AsSpan() extensions). The transitive dependency graph only required 4.5.4-4.5.5 anyway; the old pin to 4.6.3 was artificially high. Fixes #1608 Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
|
Copilot This is good, but I want something that a dependency update bot won't immediately try to re-upgrade. |
Follows the same pattern as microsoft/vs-streamjsonrpc: - Add src/Analyzers.props that sets IsAnalyzerProject=true - Import it in all 4 analyzer csproj files - In Directory.Packages.props, restore global System.Memory to 4.6.3 and add a conditional ItemGroup for IsAnalyzerProject='true' projects that overrides System.Memory down to 4.5.5 (what VS 2022 provides) This way a dependency update bot can safely bump the global System.Memory version without breaking the VS 2022 analyzer load, because the override for analyzer projects will continue to cap it at the VS-provided version. Co-authored-by: AArnott <3548+AArnott@users.noreply.github.com>
Done in the latest commit. The approach mirrors vs-streamjsonrpc exactly:
A bot can now freely bump the global |
There was a problem hiding this comment.
Pull request overview
This PR aims to fix a VS 2022 analyzer load failure caused by System.Memory assembly version mismatches by ensuring analyzer projects resolve a VS-host-compatible System.Memory package version during restore.
Changes:
- Adds
src/Analyzers.propsand imports it into the analyzer-related projects to mark them as analyzer projects. - Introduces a conditional override in
Directory.Packages.propsintended to pinSystem.Memoryto4.5.5for analyzer projects while keeping the repo-wide pin at4.6.3.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.VisualStudio.Threading.Analyzers/Microsoft.VisualStudio.Threading.Analyzers.csproj | Imports Analyzers.props to flag the project for analyzer-specific dependency pinning. |
| src/Microsoft.VisualStudio.Threading.Analyzers.VisualBasic/Microsoft.VisualStudio.Threading.Analyzers.VisualBasic.csproj | Imports Analyzers.props to flag the project for analyzer-specific dependency pinning. |
| src/Microsoft.VisualStudio.Threading.Analyzers.CSharp/Microsoft.VisualStudio.Threading.Analyzers.CSharp.csproj | Imports Analyzers.props to flag the project for analyzer-specific dependency pinning. |
| src/Microsoft.VisualStudio.Threading.Analyzers.CodeFixes/Microsoft.VisualStudio.Threading.Analyzers.CodeFixes.csproj | Imports Analyzers.props to flag the project for analyzer-specific dependency pinning. |
| src/Analyzers.props | Defines IsAnalyzerProject=true intended for conditional CPM overrides. |
| Directory.Packages.props | Adds an analyzer-only conditional override for System.Memory to 4.5.5. |
Amadeusz Wieczorek (AmadeusW)
left a comment
There was a problem hiding this comment.
Approving with a comment
The
Microsoft.VisualStudio.Threading.Analyzerspackage failed to load in VS 2022 withFileNotFoundExceptionforSystem.Memory, Version=4.0.2.0. VS 2022 shipsSystem.Memory 4.5.5(assembly version4.0.1.1), but the package version was pinned to4.6.3(assembly version4.0.2.0), causing a binding failure at analyzer load time.Changes
Directory.Packages.props: DowngradeSystem.Memorypin from4.6.3→4.5.5The transitive dependency graph only required
4.5.4–4.5.5(viaMicrosoft.CodeAnalysis.Common,System.Collections.Immutable,System.IO.Pipelines); the4.6.3pin was artificially inflated. AllMemory/SpanAPIs used by the analyzers (ReadOnlyMemory<char>,ReadOnlySpan<char>,.AsMemory(),.AsSpan()) are present in4.5.x. As a side effect,System.Buffersdrops from4.6.1to4.5.1, also aligning with what VS 2022 provides.