Skip to content

fix(mocks): CS9262 in generated mock members on VS 17.14 (Roslyn 4.14)#6392

Merged
thomhurst merged 1 commit into
mainfrom
fix/6370-orp-extension-property-cs9262
Jul 12, 2026
Merged

fix(mocks): CS9262 in generated mock members on VS 17.14 (Roslyn 4.14)#6392
thomhurst merged 1 commit into
mainfrom
fix/6370-orp-extension-property-cs9262

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Summary

Fixes #6370 — since v1.44.0, any Type.Mock() usage failed to compile under Visual Studio 17.14 with:

CS9262: Cannot use 'OverloadResolutionPriorityAttribute' on this member. (×3)

Root cause

The *_MockMembers.g.cs polyfills introduced in #5881 apply [OverloadResolutionPriority(-1)] to the three extension-block properties (Invocations, Behavior, DefaultValueProvider) — hence exactly three errors. Roslyn 4.14 (VS 17.14) rejects the attribute on non-indexer extension properties with CS9262; the Roslyn shipped with the .NET 10 SDK accepts it, which is why CI and local builds never caught it.

Fix

Remove the attribute from the property polyfills only. It was inert there: the polyfill is skipped whenever the mocked type declares a member of the same name, so no same-name member can coexist in the containing type for the attribute to rank against. Method polyfills keep it — the attribute is legal on ordinary static methods since Roslyn 4.12.

Testing

  • TUnit.Mocks.SourceGenerator.Tests: 76/76 pass; all 58 affected snapshots re-verified — every diff is purely the three attribute-line removals.
  • TUnit.Mocks.Tests (net10.0): 1158/1158 pass — mock.Invocations / mock.Behavior / mock.DefaultValueProvider ergonomics unchanged.
  • CS9262 itself is not reproducible in-repo (test infra compiles with latest Roslyn, which permits the attribute); the snapshots are the regression guard, with a code comment explaining the constraint.

… polyfills

VS 17.14 (Roslyn 4.14) rejects the attribute on non-indexer extension
properties with CS9262, so the generated *_MockMembers.g.cs failed to
compile for any mocked type on that compiler. The attribute ranked
nothing anyway: the polyfill is skipped entirely when the mocked type
declares a member of the same name, so no same-name competition can
exist within the containing type. Method polyfills keep the attribute
(legal on methods since Roslyn 4.12).

Fixes #6370
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@claude

claude Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Summary: This is a narrowly-scoped fix for #6370 (CS9262 under VS 17.14/Roslyn 4.14). MockMembersBuilder.cs stops emitting [OverloadResolutionPriority(-1)] on the three extension-block property polyfills (Invocations, Behavior, DefaultValueProvider), since Roslyn 4.14 rejects that attribute on non-indexer extension properties. Method polyfills correctly retain the attribute. The 58 updated .verified.txt snapshots match the generator change one-for-one, with no .received.txt files committed.

Verified independently:

  • The "attribute was inert on properties" claim holds — each property polyfill is only emitted when the mocked type has no same-name member (emitInvocations = !userNames.Contains("Invocations"), etc.), so there's never a competing candidate for the priority to rank against, and properties can't be overloaded anyway.
  • No dual-mode (source-gen vs reflection) concern — mocking has no reflection-mode counterpart to keep in sync.
  • No .received.txt files, no VSTest references, no AOT/perf-sensitive surface touched.

🤖 Generated with automated code review

@thomhurst thomhurst merged commit 773eaf7 into main Jul 12, 2026
12 of 13 checks passed
@thomhurst thomhurst deleted the fix/6370-orp-extension-property-cs9262 branch July 12, 2026 06:43
This was referenced Jul 13, 2026
This was referenced Jul 13, 2026
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

Successfully merging this pull request may close these issues.

[Bug]: Mock doesn't compile since v1.44 (CS9262 : OverloadResolutionPriorityAttribute)

1 participant