[release/9.0-staging] Ignore modopts/modreqs for UnsafeAccessor
field targets
#109709
+48
−24
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.
Backport of #109694 to release/9.0-staging
/cc @AaronRobinsonMSFT
Customer Impact
Customer reported issue: #109665. This was originally found in a MSBuild BinLog reader scenario. The specific issue is fields that are marked as
volatile
in C# aren't discoverable when usingUnsafeAccessor
s and as such if someone writes the following, it is unable to be accessed.This can't be discovered because the
volatile
in C# is embedded via a modreq and there is no place to describe that using theUnsafeAccessorAttribute
.The general issue is that when discovering the target field member, we currently require a complete match for fields. One could imagine we add some support for this, but given they are generally considered compiler directives, there is little value in considering them in this lookup scenario and so they should be ignored on fields. This is already done in the method case, but the relaxation was missed on field discovery.
Regression
Early in the .NET 9 release, the logic for signature comparrison was rewritten and regressed some unsupported issues and has uncovered a regression in a supported scenario.
Testing
Tests for the particular issue were added. I reached out to the Roslyn compiler team and verified the added test case is the only scenario where this occurs.
Risk
Low This is a permissive change on the way fields are looked-up and their types compared. Since C#/VB.NET don't provide other modopts/modreqs it is unlikely this will impact any other scenario.