Skip to content

Don't allow inlining the NativeAOT-only unsafe accessor #116646

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

Merged
merged 2 commits into from
Jun 13, 2025
Merged

Conversation

jkoritzinsky
Copy link
Member

Should unblock dotnet/efcore#36242

Implements workaround mentioned in dotnet/efcore#36242 (comment)

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Prevents the NativeAOT-only unsafe accessor from being inlined by marking the extern CreateObjectArrayDelegate method with NoInlining, addressing a workaround needed by EF Core.

  • Added [MethodImpl(MethodImplOptions.NoInlining)] to the static extern call site.
  • Targets the CreateObjectArrayDelegate method in DelegateHelpers to ensure it isn’t inlined by the JIT/AOT compiler.
Comments suppressed due to low confidence (1)

src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/DelegateHelpers.cs:33

  • [nitpick] Add a brief comment above this attribute to explain why NoInlining is required (e.g., to prevent inlining of the NativeAOT-only unsafe accessor), providing context for future maintainers.
[MethodImpl(MethodImplOptions.NoInlining)]

Copy link
Contributor

Tagging subscribers to this area: @cston
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Jun 13, 2025

There may be a few more that deserve the same treatment:

[return: UnsafeAccessorType("System.Windows.Forms.ComponentModel.Com2Interop.ComNativeDescriptor, System.Windows.Forms")]
static extern object CreateComNativeDescriptor();
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "GetDefaultInstance")]
[return: UnsafeAccessorType("System.Security.Principal.WindowsPrincipal, System.Security.Principal.Windows")]

An alternative for this one is wrap the caller with #if TARGET_WINDOWS instead of catching and rethrowing an exception.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkoritzinsky
Copy link
Member Author

/ba-g wasm build failure is unrelated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants