From dab28b9c887944ade2f22a07412bb08e26f202e6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 22 Oct 2025 17:53:02 +0000 Subject: [PATCH 1/2] Initial plan From 74d56cd1aa62df8ce02300bad2276b1e4e3ab3db Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 22 Oct 2025 18:05:02 +0000 Subject: [PATCH 2/2] Add breaking change documentation for DAMT.All annotation restrictions Co-authored-by: sbomer <787361+sbomer@users.noreply.github.com> --- docs/core/compatibility/10.0.md | 1 + .../10/damt-all-restricted-annotations.md | 94 +++++++++++++++++++ docs/core/compatibility/toc.yml | 2 + 3 files changed, 97 insertions(+) create mode 100644 docs/core/compatibility/reflection/10/damt-all-restricted-annotations.md diff --git a/docs/core/compatibility/10.0.md b/docs/core/compatibility/10.0.md index 917d54605a92a..f526e6bf57d8e 100644 --- a/docs/core/compatibility/10.0.md +++ b/docs/core/compatibility/10.0.md @@ -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 | diff --git a/docs/core/compatibility/reflection/10/damt-all-restricted-annotations.md b/docs/core/compatibility/reflection/10/damt-all-restricted-annotations.md new file mode 100644 index 0000000000000..52d2b9086b973 --- /dev/null +++ b/docs/core/compatibility/reflection/10/damt-all-restricted-annotations.md @@ -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 , , and APIs use more restricted annotations instead of `DAMT.All`. This change affects scenarios where you implement the interface or derive from . + +## 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 or derive from . + +```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 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 or derive from , review your code and update annotations to align with the new behavior. Specifically: + +1. Replace `DAMT.All` annotations with more restricted annotations, such as , , 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 + +- +- +- + +## See also + +- [Prepare .NET libraries for trimming](/dotnet/core/deploying/trimming/prepare-libraries-for-trimming) diff --git a/docs/core/compatibility/toc.yml b/docs/core/compatibility/toc.yml index 2b7ed52bc3c3f..4f7a00d62a4ac 100644 --- a/docs/core/compatibility/toc.yml +++ b/docs/core/compatibility/toc.yml @@ -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