[Breaking change]: System.Reflection no longer uses the IntPtr type for function pointer types #34623
Closed
1 of 3 tasks
Labels
breaking-change
Indicates a .NET Core breaking change
📌 seQUESTered
Identifies that an issue has been imported into Quest.
Description
As a new reflection feature, a function pointer type will be a
System.Type
instance with new capabilities such asType.IsFunctionPointer
. Previously, theSystem.Type
instance returned was theIntPtr
type.Using
System.Type
is this manner is similar to how other types are exposed such as pointers (Type.IsPointer
) and arrays (Type.IsArray
).For more information, see the API issue and Design.
This new functionality is currently implemented in the CoreCLR runtime and in
System.Reflection.MetadataLoadContext
. Support for the Mono and NativeAOT runtimes are expected later.A function pointer instance, which is a physical address to a function, continues to be represented as an
IntPtr
; only the reflection type was changed with this feature.Version
.NET 8 Preview 2
Previous behavior
The
IntPtr
type was used for a function pointer type such as withtypeof(delegate*<void>())
or when obtaining a function pointer type through reflection such as withFieldInfo.FieldType
. This did not allow any access to the parameter types, return type or calling conventions.New behavior
The
System.Type
is now used for a function pointer type with access to the parameter types, return type and calling conventions.Type of breaking change
Reason for change
Adds the capability to obtain function pointer metadata including parameter types, the return type and the calling conventions. Function pointer support was added with C# 9 and .NET 6 but reflection support was not added at that time.
Recommended action
Any general-purpose reflection code that wants to support function pointers should use the new API
Type.IsFunctionPointer
if special treatment is required for function pointers.Feature area
Other (please put exact area in description textbox)
Affected APIs
For function pointer types, the C# keyword
typeof
and these reflection APIs now return aType
instance with new capabilities\APIs instead of the semantics returned by theIntPtr
type.Associated WorkItem - 70834
The text was updated successfully, but these errors were encountered: