Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UnsafeAccessor] throws MissingFieldException on .NET 9 when used on unspeakable fields #109943

Closed
Sergio0694 opened this issue Nov 19, 2024 · 3 comments · Fixed by #109944
Closed
Labels
area-System.Runtime.CompilerServices in-pr There is an active PR which will close this issue when it is merged regression-from-last-release
Milestone

Comments

@Sergio0694
Copy link
Contributor

Sergio0694 commented Nov 19, 2024

Description

Spotted while porting my ComputeSharp samples to .NET 9 (see here). It seems that [UnsafeAccessor] is broken in .NET 9 when used to access unspeakable fields (captured primary constructor parameters being a common example).

Reproduction Steps

using System.Runtime.CompilerServices;

Blah blah = new("Bob");

string name = Blah.GetName(in blah);

Console.WriteLine(name);

public readonly struct Blah(string name)
{
    public string EnsureCaptured => name;

    [UnsafeAccessor(UnsafeAccessorKind.Field, Name = "<name>P")]
    public static extern ref readonly string GetName(ref readonly Blah value);
}

Expected behavior

Should work as expected.

Actual behavior

Sergio0694/ComputeSharp#871

Regression?

Yes. Works fine on .NET 8.

Known Workarounds

None that I can think of.

Configuration

  • .NET SDK 9.0.100
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices
See info in area-owners.md if you want to be subscribed.

@Sergio0694
Copy link
Contributor Author

@AaronRobinsonMSFT it seems the problem is the ref readonly return. If I change it to just ref, then it works on .NET 9 as well. I suppose I can use that as a workaround for now, but shouldn't that work too though? It was working fine on .NET 8, and it feels like it should? 🤔

@AaronRobinsonMSFT
Copy link
Member

It is possible this was fixed in #109694. Can you check the nightly build?

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Nov 19, 2024
@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 10.0.0 milestone Nov 19, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Nov 19, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.CompilerServices in-pr There is an active PR which will close this issue when it is merged regression-from-last-release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants