Skip to content

Add more detail to GetFunctionPointerForDelegate docs #11401

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion xml/System.Runtime.InteropServices/Marshal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3946,10 +3946,15 @@ The code retrieves a reference to an instance of Microsoft Word successfully. Ho

You must manually keep the delegate from being collected by the garbage collector from managed code. The garbage collector does not track references to unmanaged code.

This API is unsupported in environments that do not support dynamic entrypoint allocation, such as `ProcessDynamicCodePolicy` on Windows, `execmem off` in SELinux, or WebAssembly.

It is recommended to use function pointers and (xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute) instead. Function pointers are more efficient, easier to use correctly, and supported in all environments.

]]></format>
</remarks>
<exception cref="T:System.ArgumentException">The <paramref name="d" /> parameter is a generic type definition.</exception>
<exception cref="T:System.ArgumentNullException">The <paramref name="d" /> parameter is <see langword="null" />.</exception>
<exception cref="T:System.PlatformNotSupportedException">Dynamic entrypoint allocation is not supported in the current environment.</exception>
</Docs>
</Member>
<Member MemberName="GetFunctionPointerForDelegate&lt;TDelegate&gt;">
Expand Down Expand Up @@ -4014,11 +4019,15 @@ The code retrieves a reference to an instance of Microsoft Word successfully. Ho
The delegate `d` is converted to a function pointer that can be passed to unmanaged code by using [the default platform calling convention](/dotnet/standard/native-interop/calling-conventions#platform-default-calling-convention). You can set the calling convention by applying the <xref:System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute> to the delegate.

You must manually keep the delegate from being collected by the garbage collector from managed code. The garbage collector does not track references to unmanaged code.


This API is unsupported in environments that do not support dynamic entrypoint allocation, such as `ProcessDynamicCodePolicy` on Windows, `execmem off` in SELinux, or WebAssembly.

It is recommended to use function pointers and (xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute) instead. Function pointers are more efficient, easier to use correctly, and supported in all environments.
]]></format>
</remarks>
<exception cref="T:System.ArgumentException">The <paramref name="d" /> parameter is a generic type definition.</exception>
<exception cref="T:System.ArgumentNullException">The <paramref name="d" /> parameter is <see langword="null" />.</exception>
<exception cref="T:System.PlatformNotSupportedException">Dynamic entrypoint allocation is not supported in the current environment.</exception>
</Docs>
</Member>
<Member MemberName="GetHINSTANCE">
Expand Down