-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-System.Runtime.CompilerServicesin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged
Milestone
Description
Description
When trying to access volatile string
private field through UnsafeAccessorAttribute
, MissingFieldException
is thrown.
Reproduction Steps
using System;
using System.Runtime.CompilerServices;
var a = new A();
Console.WriteLine(GetSetFoo(a));
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "foo")]
extern static ref string GetSetFoo(A args);
class A { private volatile string? foo = "Bar"; }
Expected behavior
The program output is Bar
.
Actual behavior
Unhandled exception. System.MissingFieldException: Field not found: 'A.foo'.
at Program.<<Main>$>g__GetSetFoo|0_0(A args)
at Program.<Main>$(String[] args) in D:\unsafeaccessor\Program.cs:line 5
Regression?
No response
Known Workarounds
No response
Configuration
This seems to be broken both in .NET 8 and .NET 9 with CoreCLR runtime. Tested on Windows and macOS.
Other information
The question of modreqs/modopts came up in the original feature proposal and this was the answer (#81741 (comment)):
And how would this interact with modreqs and modopts that can't be specified in C# (e.g. the IsExternalInit modifier on init property setters / volatile fields etc)?
Yeah, modreqs and modopts would be complicated. I think we will skip modreqs and modopts for the signature match.
This originally came up in KirillOsenkov/MSBuildStructuredLog#834.
Metadata
Metadata
Assignees
Labels
area-System.Runtime.CompilerServicesin-prThere is an active PR which will close this issue when it is mergedThere is an active PR which will close this issue when it is merged