Closed
Description
Description
It appears that UnsafeAccessor
may not be working on .NET 9 as expected with JIT configuration, but continues to work with NativeAOT.
Reproduction Steps
Given simple program created from a default console template:
using System.Runtime.CompilerServices;
var holder = new Holder<float>();
Console.WriteLine(ArrayRef(holder).Length); // 8
[UnsafeAccessor(UnsafeAccessorKind.Field, Name = "array")]
static extern ref float[] ArrayRef(Holder<float> instance);
class Holder<T>
{
T[] array = new T[8];
}
Expected behavior
> dotnet run -c Release -f net9.0
8
Actual behavior
> dotnet run -c Release net8.0
8
> dotnet run -c Release net9.0
Unhandled exception. System.MissingFieldException: Field not found: 'Holder`1.array'.
at Program.<<Main>$>g__ArrayRef|0_0(Holder`1 instance)
at Program.<Main>$(String[] args) in ***\AccessorRepro\Program.cs:line 4
> dotnet publish -f net8.0 -o . -p:PublishAot=true; .\AccessorRepro.exe
8
> dotnet publish -f net9.0 -o . -p:PublishAot=true; .\AccessorRepro.exe
8
Regression?
Yes
Known Workarounds
Using reflection 😢
Configuration
.NET SDK:
Version: 9.0.100-rc.2.24468.2
Commit: c204043de1
Workload version: 9.0.100-manifests.8fbc914b
MSBuild version: 17.12.0-preview-24467-02+988196b1c
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.100-rc.2.24468.2\
but did also reproduce with RC.1
Other information
No response