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

[Breaking change]: System.Reflection no longer uses the IntPtr type for function pointer types #34623

Closed
1 of 3 tasks
steveharter opened this issue Mar 16, 2023 · 0 comments · Fixed by #34646
Closed
1 of 3 tasks
Assignees
Labels
breaking-change Indicates a .NET Core breaking change doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@steveharter
Copy link
Member

steveharter commented Mar 16, 2023

Description

As a new reflection feature, a function pointer type will be a System.Type instance with new capabilities such as Type.IsFunctionPointer. Previously, the System.Type instance returned was the IntPtr 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 with typeof(delegate*<void>()) or when obtaining a function pointer type through reflection such as with FieldInfo.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

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code may require source changes to compile successfully.
  • Behavioral change: Existing binaries may behave differently at run time.

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 a Type instance with new capabilities\APIs instead of the semantics returned by the IntPtr type.

namespace System.Reflection
{
    public abstract class FieldInfo
    {
        public Type FieldType() {get;}
    }
    public abstract class PropertyInfo
    {
        public Type PropertyType() {get;}
    }
    public abstract class ParameterInfo
    {
        public Type ParameterType() {get;}
    }
}

Associated WorkItem - 70834

@steveharter steveharter added doc-idea Indicates issues that are suggestions for new topics [org][type][category] breaking-change Indicates a .NET Core breaking change Pri1 High priority, do before Pri2 and Pri3 labels Mar 16, 2023
@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label Mar 16, 2023
@steveharter steveharter assigned buyaa-n and unassigned buyaa-n Mar 16, 2023
@steveharter steveharter changed the title [Breaking change]: reflection now uses System.Type instead of IntPtr for function pointer types [Breaking change]: System.Reflection no longer uses the IntPtr type for function pointer types Mar 16, 2023
@gewarren gewarren added 🗺️ reQUEST Triggers an issue to be imported into Quest. and removed ⌚ Not Triaged Not triaged labels Mar 17, 2023
@github-actions github-actions bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels Mar 17, 2023
@ghost ghost added the in-pr This issue will be closed (fixed) by an active pull request. label Mar 17, 2023
@ghost ghost removed the in-pr This issue will be closed (fixed) by an active pull request. label Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Indicates a .NET Core breaking change doc-idea Indicates issues that are suggestions for new topics [org][type][category] Pri1 High priority, do before Pri2 and Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants