Skip to content

Commit 74d56cd

Browse files
Copilotsbomer
andcommitted
Add breaking change documentation for DAMT.All annotation restrictions
Co-authored-by: sbomer <[email protected]>
1 parent dab28b9 commit 74d56cd

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
5353
| [LDAP DirectoryControl parsing is now more stringent](core-libraries/10.0/ldap-directorycontrol-parsing.md) | Behavioral change | Preview 1 |
5454
| [MacCatalyst version normalization](core-libraries/10.0/maccatalyst-version-normalization.md) | Behavioral change | Preview 1 |
5555
| [.NET runtime no longer provides default termination signal handlers](core-libraries/10.0/sigterm-signal-handler.md) | Behavioral change | Preview 5 |
56+
| [Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers](reflection/10/damt-all-restricted-annotations.md) | Source incompatible/behavioral change | Preview 1 |
5657
| [System.Linq.AsyncEnumerable included in core libraries](core-libraries/10.0/asyncenumerable.md) | Source incompatible | Preview 1 |
5758
| [Type.MakeGenericSignatureType argument validation](reflection/10/makegeneric-signaturetype-validation.md) | Behavioral change | Preview 3 |
5859
| [YMM embedded rounding removed from AVX10.2](core-libraries/10.0/ymm-embedded-rounding.md) | Behavioral change | Preview 5 |
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
title: "Breaking change: Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers"
3+
description: Learn about the .NET 10 breaking change in core .NET libraries where InvokeMember, FindMembers, and DeclaredMembers APIs use more restricted annotations instead of DAMT.All.
4+
ms.date: 10/22/2025
5+
ai-usage: ai-assisted
6+
---
7+
# Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers
8+
9+
Starting in .NET 10, the <xref:System.Reflection.IReflect.InvokeMember%2A?displayProperty=nameWithType>, <xref:System.Type.FindMembers%2A?displayProperty=nameWithType>, and <xref:System.Reflection.TypeInfo.DeclaredMembers?displayProperty=nameWithType> APIs use more restricted annotations instead of `DAMT.All`. This change affects scenarios where you implement the <xref:System.Reflection.IReflect> interface or derive from <xref:System.Reflection.TypeInfo>.
10+
11+
## Version introduced
12+
13+
.NET 10 Preview 1
14+
15+
## Previous behavior
16+
17+
Previously, the `InvokeMember`, `FindMembers`, and `DeclaredMembers` APIs used the `DAMT.All` annotation, which was overly permissive. This could result in capturing additional members, such as interface methods implemented by a class, and potentially caused runtime warnings or unsafe reflection calls.
18+
19+
```csharp
20+
public class MyType : IReflect
21+
{
22+
public MethodInfo[] GetMethods(BindingFlags bindingAttr)
23+
{
24+
// Previous behavior: DAMT.All annotation applied
25+
// This could capture additional members, including interface methods implemented by the class
26+
}
27+
}
28+
```
29+
30+
## New behavior
31+
32+
The `InvokeMember`, `FindMembers`, and `DeclaredMembers` APIs now use more restricted annotations, which provide better control over the members captured during reflection. You must update your annotations to match the new behavior if you implement <xref:System.Reflection.IReflect> or derive from <xref:System.Reflection.TypeInfo>.
33+
34+
```csharp
35+
public class MyType : IReflect
36+
{
37+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
38+
public MethodInfo[] GetMethods(BindingFlags bindingAttr)
39+
{
40+
// New behavior: More restricted annotation applied
41+
// Only public methods are captured, avoiding unintended members
42+
}
43+
}
44+
```
45+
46+
## Type of breaking change
47+
48+
This change can affect [source compatibility](../../categories.md#source-incompatible) and is a [behavioral change](../../categories.md#behavioral-change).
49+
50+
## Reason for change
51+
52+
The change was introduced to improve the accuracy of annotations in <xref:System.Reflection> APIs and to address issues caused by the overly permissive `DAMT.All` annotation. This ensures better compatibility with trimming and reflection scenarios, reduces runtime warnings, and prevents unsafe reflection calls.
53+
54+
## Recommended action
55+
56+
If you implement <xref:System.Reflection.IReflect> or derive from <xref:System.Reflection.TypeInfo>, review your code and update annotations to align with the new behavior. Specifically:
57+
58+
1. Replace `DAMT.All` annotations with more restricted annotations, such as <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicMethods?displayProperty=nameWithType>, <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicMethods?displayProperty=nameWithType>, or other appropriate types.
59+
1. Test reflection scenarios to ensure that the updated annotations capture the intended members and don't introduce runtime errors or warnings.
60+
61+
**Before:**
62+
63+
```csharp
64+
public class MyType : IReflect
65+
{
66+
public MethodInfo[] GetMethods(BindingFlags bindingAttr)
67+
{
68+
// Previous behavior: DAMT.All annotation applied
69+
}
70+
}
71+
```
72+
73+
**After:**
74+
75+
```csharp
76+
public class MyType : IReflect
77+
{
78+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
79+
public MethodInfo[] GetMethods(BindingFlags bindingAttr)
80+
{
81+
// New behavior: More restricted annotation applied
82+
}
83+
}
84+
```
85+
86+
## Affected APIs
87+
88+
- <xref:System.Reflection.IReflect.InvokeMember%2A?displayProperty=fullName>
89+
- <xref:System.Type.FindMembers%2A?displayProperty=fullName>
90+
- <xref:System.Reflection.TypeInfo.DeclaredMembers?displayProperty=fullName>
91+
92+
## See also
93+
94+
- [Prepare .NET libraries for trimming](/dotnet/core/deploying/trimming/prepare-libraries-for-trimming)

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ items:
116116
href: networking/10.0/uri-length-limits-removed.md
117117
- name: Reflection
118118
items:
119+
- name: Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers
120+
href: reflection/10/damt-all-restricted-annotations.md
119121
- name: Type.MakeGenericSignatureType argument validation
120122
href: reflection/10/makegeneric-signaturetype-validation.md
121123
- name: SDK and MSBuild

0 commit comments

Comments
 (0)