Name the guarded API in ThrowIfVerifyHasBeenRun - #1864
Merged
Conversation
The message named the calling code as "The API", pointing at the wrong place to move into a module initializer. Reading the name off a StackTrace cannot fix that: whether the guarded API has a frame of its own depends on the JIT, and on net48 in release it is inlined into the caller, so no frame index is right. The name now comes from CallerMemberName, which the compiler fills in at each call site, so it is the same under every runtime and configuration. That drops the declaring type from the message, since only the member name is available.
SimonCropp
force-pushed
the
fix-throwif-api-frame
branch
from
August 17, 2026 12:51
acc7c7b to
2c029cf
Compare
This was referenced Aug 26, 2026
This was referenced Aug 28, 2026
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.
The message named the calling code as "The API":
which points at the wrong place to move into a
[ModuleInitializer].First attempt read frame 0 instead of frame 1, and CI caught that it does not hold. Whether the guarded API has a stack frame of its own is a JIT decision: on net48 in release
VerifierSettings.IgnoreMembersis inlined into its caller, so frame 0 is the caller. No frame index is correct — with the originalGetFrame(1)the same net48 release run namesXunit.Assert.RecordException, two frames adrift, because the test lambda is inlined too.So the name now comes from
[CallerMemberName], which the compiler fills in at each of the 111 call sites. It cannot drift with inlining, costs nothing at run time, and needs noStackTrace(which also makes it safe under trimming, where frames can be stripped).Two consequences worth calling out:
CallerMemberNameonly supplies the member. It now readsThe API 'IgnoreMembers' must be called prior…. No snapshot or doc captures this message, so nothing else moved.ThrowIfVerifyHasBeenRungains an optional parameter. Source compatible, but a binary break for anything already compiled against the no-arg signature. Every caller in this repo is rebuilt together; a third party adapter shipped as a prebuilt assembly would need a recompile. That seems acceptable for 32.0.0, but it is your call.ThrowIfVerifyHasBeenRunTests.NamesTheApicalls a real guarded API and asserts the message names it and not the test. Verified across Debug and Release × net48 and net11.0 this time, since that axis is exactly what the first attempt missed.Release suites:
Verify.Testsnet48 (1197), net11.0 (1287), net9.0 (1293);StaticSettingsTests,Verify.NUnit.Tests,Verify.MSTest.Tests,Verify.XunitV3.Tests,ApplyScrubbersTests,Verify.ExceptionParsing.Testsall green.