From 02c9dedac3753ec35f0f5c4bb394761fab009f1d Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Fri, 17 Mar 2023 16:53:57 -0700 Subject: [PATCH] function pointer breaking change --- docs/core/compatibility/8.0.md | 6 +++ .../8.0/function-pointer-reflection.md | 45 +++++++++++++++++++ docs/core/compatibility/toc.yml | 10 +++++ 3 files changed, 61 insertions(+) create mode 100644 docs/core/compatibility/reflection/8.0/function-pointer-reflection.md diff --git a/docs/core/compatibility/8.0.md b/docs/core/compatibility/8.0.md index 6ecc33e223ad5..065964e06ae75 100644 --- a/docs/core/compatibility/8.0.md +++ b/docs/core/compatibility/8.0.md @@ -49,6 +49,12 @@ If you're migrating an app to .NET 8, the breaking changes listed here might aff | ------------------------------------------------------------------------------- | ----------------- | ---------- | | [TwoDigitYearMax default is 2049](globalization/8.0/twodigityearmax-default.md) | Behavioral change | Preview 1 | +## Reflection + +| Title | Type of change | Introduced | +| ------------------------------------------------------------------------------------------------- | ----------------- | ---------- | +| [IntPtr no longer used for function pointer types](reflection/8.0/function-pointer-reflection.md) | Behavioral change | Preview 2 | + ## SDK | Title | Type of change | Introduced | diff --git a/docs/core/compatibility/reflection/8.0/function-pointer-reflection.md b/docs/core/compatibility/reflection/8.0/function-pointer-reflection.md new file mode 100644 index 0000000000000..65e3d8410581e --- /dev/null +++ b/docs/core/compatibility/reflection/8.0/function-pointer-reflection.md @@ -0,0 +1,45 @@ +--- +title: "Breaking change: IntPtr no longer used for function pointer types" +description: Learn about a breaking change in .NET 8 SDK where System.Reflection uses a System.Type instance to represent a function pointer. +ms.date: 03/17/2023 +--- +# IntPtr no longer used for function pointer types + +As a new reflection feature, a function pointer type is now a instance with new capabilities such as . Previously, the instance returned was the type. + +Using in this manner is similar to how other types are exposed, such as pointers () and arrays (). + +This new functionality is currently implemented in the CoreCLR runtime and in . Support for the Mono and NativeAOT runtimes is expected later. + +A function pointer instance, which is a physical address to a function, continues to be represented as an ; only the reflection type has changed. + +## Previous behavior + +Previously, `typeof(delegate*())` returned the type for a function pointer type. Similarly, reflection also returned this type for a function pointer type, such as with . The type didn't allow any access to the parameter types, return type, or calling conventions. + +## New behavior + +`typeof` and reflection now use for a function pointer type, which provides access to the parameter types, return type, and calling conventions. + +## Version introduced + +.NET 8 Preview 2 + +## Type of breaking change + +This change is a [behavioral change](../../categories.md#behavioral-change). + +## Reason for change + +This 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 wasn't added at that time. + +## Recommended action + +If you want your code to support function pointers and to treat them specially, use the new API. + +## Affected APIs + +- `typeof` keyword +- +- +- diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index f0c1a3c8c2015..1ceea34118800 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -44,6 +44,10 @@ items: items: - name: TwoDigitYearMax default is 2049 href: globalization/8.0/twodigityearmax-default.md + - name: Reflection + items: + - name: IntPtr no longer used for function pointer types + href: reflection/8.0/function-pointer-reflection.md - name: SDK items: - name: CLI console output uses UTF-8 @@ -1278,6 +1282,12 @@ items: href: networking/5.0/winhttphandler-removed-from-runtime.md - name: .NET Core 2.0-3.0 href: networking.md + - name: Reflection + items: + - name: .NET 8 + items: + - name: IntPtr no longer used for function pointer types + href: reflection/8.0/function-pointer-reflection.md - name: SDK and MSBuild items: - name: .NET 8