Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/core/compatibility/10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
| [LDAP DirectoryControl parsing is now more stringent](core-libraries/10.0/ldap-directorycontrol-parsing.md) | Behavioral change | Preview 1 |
| [MacCatalyst version normalization](core-libraries/10.0/maccatalyst-version-normalization.md) | Behavioral change | Preview 1 |
| [.NET runtime no longer provides default termination signal handlers](core-libraries/10.0/sigterm-signal-handler.md) | Behavioral change | Preview 5 |
| [Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers](reflection/10/damt-all-restricted-annotations.md) | Source incompatible/behavioral change | Preview 1 |
| [System.Linq.AsyncEnumerable included in core libraries](core-libraries/10.0/asyncenumerable.md) | Source incompatible | Preview 1 |
| [Type.MakeGenericSignatureType argument validation](reflection/10/makegeneric-signaturetype-validation.md) | Behavioral change | Preview 3 |
| [YMM embedded rounding removed from AVX10.2](core-libraries/10.0/ymm-embedded-rounding.md) | Behavioral change | Preview 5 |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
title: "Breaking change: Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers"
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.
ms.date: 10/22/2025
ai-usage: ai-assisted
---
# Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers

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>.

## Version introduced

.NET 10 Preview 1

## Previous behavior

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.

```csharp
public class MyType : IReflect
{
public MethodInfo[] GetMethods(BindingFlags bindingAttr)
{
// Previous behavior: DAMT.All annotation applied
// This could capture additional members, including interface methods implemented by the class
}
}
```

## New behavior

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>.

```csharp
public class MyType : IReflect
{
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
public MethodInfo[] GetMethods(BindingFlags bindingAttr)
{
// New behavior: More restricted annotation applied
// Only public methods are captured, avoiding unintended members
}
}
```

## Type of breaking change

This change can affect [source compatibility](../../categories.md#source-incompatible) and is a [behavioral change](../../categories.md#behavioral-change).

## Reason for change

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.

## Recommended action

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:

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.
1. Test reflection scenarios to ensure that the updated annotations capture the intended members and don't introduce runtime errors or warnings.

**Before:**

```csharp
public class MyType : IReflect
{
public MethodInfo[] GetMethods(BindingFlags bindingAttr)
{
// Previous behavior: DAMT.All annotation applied
}
}
```

**After:**

```csharp
public class MyType : IReflect
{
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)]
public MethodInfo[] GetMethods(BindingFlags bindingAttr)
{
// New behavior: More restricted annotation applied
}
}
```

## Affected APIs

- <xref:System.Reflection.IReflect.InvokeMember%2A?displayProperty=fullName>
- <xref:System.Type.FindMembers%2A?displayProperty=fullName>
- <xref:System.Reflection.TypeInfo.DeclaredMembers?displayProperty=fullName>

## See also

- [Prepare .NET libraries for trimming](/dotnet/core/deploying/trimming/prepare-libraries-for-trimming)
2 changes: 2 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ items:
href: networking/10.0/uri-length-limits-removed.md
- name: Reflection
items:
- name: Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers
href: reflection/10/damt-all-restricted-annotations.md
- name: Type.MakeGenericSignatureType argument validation
href: reflection/10/makegeneric-signaturetype-validation.md
- name: SDK and MSBuild
Expand Down
Loading