Skip to content

Commit 0571ad4

Browse files
authored
function pointer breaking change (#34646)
1 parent 70b25ff commit 0571ad4

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

docs/core/compatibility/8.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ If you're migrating an app to .NET 8, the breaking changes listed here might aff
4949
| ------------------------------------------------------------------------------- | ----------------- | ---------- |
5050
| [TwoDigitYearMax default is 2049](globalization/8.0/twodigityearmax-default.md) | Behavioral change | Preview 1 |
5151

52+
## Reflection
53+
54+
| Title | Type of change | Introduced |
55+
| ------------------------------------------------------------------------------------------------- | ----------------- | ---------- |
56+
| [IntPtr no longer used for function pointer types](reflection/8.0/function-pointer-reflection.md) | Behavioral change | Preview 2 |
57+
5258
## SDK
5359

5460
| Title | Type of change | Introduced |
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: "Breaking change: IntPtr no longer used for function pointer types"
3+
description: Learn about a breaking change in .NET 8 SDK where System.Reflection uses a System.Type instance to represent a function pointer.
4+
ms.date: 03/17/2023
5+
---
6+
# IntPtr no longer used for function pointer types
7+
8+
As a new reflection feature, a function pointer type is now a <xref:System.Type?displayProperty=nameWithType> instance with new capabilities such as <xref:System.Type.IsFunctionPointer?displayProperty=nameWithType>. Previously, the <xref:System.Type?displayProperty=nameWithType> instance returned was the <xref:System.IntPtr> type.
9+
10+
Using <xref:System.Type?displayProperty=nameWithType> in this manner is similar to how other types are exposed, such as pointers (<xref:System.Type.IsPointer?displayProperty=nameWithType>) and arrays (<xref:System.Type.IsArray?displayProperty=nameWithType>).
11+
12+
This new functionality is currently implemented in the CoreCLR runtime and in <xref:System.Reflection.MetadataLoadContext>. Support for the Mono and NativeAOT runtimes is expected later.
13+
14+
A function pointer instance, which is a physical address to a function, continues to be represented as an <xref:System.IntPtr>; only the reflection type has changed.
15+
16+
## Previous behavior
17+
18+
Previously, `typeof(delegate*<void>())` returned the <xref:System.IntPtr?displayProperty=fullName> type for a function pointer type. Similarly, reflection also returned this type for a function pointer type, such as with <xref:System.Reflection.FieldInfo.FieldType?displayProperty=nameWithType>. The <xref:System.IntPtr> type didn't allow any access to the parameter types, return type, or calling conventions.
19+
20+
## New behavior
21+
22+
`typeof` and reflection now use <xref:System.Type?displayProperty=fullName> for a function pointer type, which provides access to the parameter types, return type, and calling conventions.
23+
24+
## Version introduced
25+
26+
.NET 8 Preview 2
27+
28+
## Type of breaking change
29+
30+
This change is a [behavioral change](../../categories.md#behavioral-change).
31+
32+
## Reason for change
33+
34+
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.
35+
36+
## Recommended action
37+
38+
If you want your code to support function pointers and to treat them specially, use the new <xref:System.Type.IsFunctionPointer?displayProperty=nameWithType> API.
39+
40+
## Affected APIs
41+
42+
- `typeof` keyword
43+
- <xref:System.Reflection.FieldInfo.FieldType?displayProperty=fullName>
44+
- <xref:System.Reflection.PropertyInfo.PropertyType?displayProperty=fullName>
45+
- <xref:System.Reflection.ParameterInfo.ParameterType?displayProperty=fullName>

docs/core/compatibility/toc.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ items:
4444
items:
4545
- name: TwoDigitYearMax default is 2049
4646
href: globalization/8.0/twodigityearmax-default.md
47+
- name: Reflection
48+
items:
49+
- name: IntPtr no longer used for function pointer types
50+
href: reflection/8.0/function-pointer-reflection.md
4751
- name: SDK
4852
items:
4953
- name: CLI console output uses UTF-8
@@ -1278,6 +1282,12 @@ items:
12781282
href: networking/5.0/winhttphandler-removed-from-runtime.md
12791283
- name: .NET Core 2.0-3.0
12801284
href: networking.md
1285+
- name: Reflection
1286+
items:
1287+
- name: .NET 8
1288+
items:
1289+
- name: IntPtr no longer used for function pointer types
1290+
href: reflection/8.0/function-pointer-reflection.md
12811291
- name: SDK and MSBuild
12821292
items:
12831293
- name: .NET 8

0 commit comments

Comments
 (0)