-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add breaking change documentation for DAMT.All replacement in System.Reflection APIs #48922
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gewarren
merged 10 commits into
main
from
copilot/fix-bfc60c08-b60c-4054-9c4d-c84296ad7fae
Nov 14, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
42fb275
Initial plan
Copilot ab1aada
Add breaking change documentation for DAMT.All replacement in reflect…
Copilot 7e4eb6d
Fix API references in reflection breaking change documentation
Copilot c7051b3
Add Reflection section to .NET 10 breaking changes overview
Copilot 24c288a
Update snippet projects to target net9.0 and fix VB namespace
Copilot 385454a
human edits
gewarren 7b0b176
don't always list apis
gewarren e9d7276
rename folder
gewarren 8075dc6
fix links
gewarren a478864
Merge branch 'main' into copilot/fix-bfc60c08-b60c-4054-9c4d-c84296ad…
gewarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
docs/core/compatibility/reflection/10/ireflect-damt-annotations.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --- | ||
| title: "Breaking change: More restricted annotations on InvokeMember/FindMembers/DeclaredMembers" | ||
| description: "Learn about the breaking change in .NET 10 where System.Reflection APIs InvokeMember, FindMembers, and DeclaredMembers use more restricted annotations instead of DynamicallyAccessedMemberTypes.All." | ||
| ms.date: 10/09/2025 | ||
| ai-usage: ai-generated | ||
| --- | ||
|
|
||
| # More restricted annotations on InvokeMember/FindMembers/DeclaredMembers | ||
|
|
||
| Starting in .NET 10, the <xref:System.Reflection> APIs <xref:System.Reflection.IReflect.InvokeMember%2A>, <xref:System.Type.FindMembers%2A>, and <xref:System.Reflection.TypeInfo.DeclaredMembers> use more restricted annotations instead of <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All?displayProperty=nameWithType>. | ||
|
|
||
| This change affects scenarios where developers implement the <xref:System.Reflection.IReflect> interface or derive from <xref:System.Reflection.TypeInfo>. The previous use of <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All?displayProperty=nameWithType> was overly permissive and could lead to unintended behavior, such as capturing interface methods implemented by a class or generating warnings due to unsafe reflection calls. | ||
|
|
||
| ## Version introduced | ||
|
|
||
| .NET 10 | ||
|
|
||
| ## Previous behavior | ||
|
|
||
| Previously, the [affected APIs](#affected-apis) used the <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All?displayProperty=nameWithType> annotation, which was overly permissive. This could result in capturing additional members, such as interface methods implemented by a class, and potentially cause runtime warnings or unsafe reflection calls. | ||
|
|
||
| ## New behavior | ||
|
|
||
| The [affected APIs](#affected-apis) now use more restricted annotations, which provide better control over the members captured during reflection. | ||
|
|
||
| ## Type of breaking change | ||
|
|
||
| This change is a [behavioral change](../../categories.md#behavioral-change) and can affect [source compatibility](../../categories.md#source-compatibility). | ||
|
|
||
| ## 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 <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All?displayProperty=nameWithType> annotation. This ensures better compatibility with trimming and reflection scenarios, reduces run-time 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 <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All?displayProperty=nameWithType> 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. | ||
|
|
||
| The following code snippet shows an example. | ||
|
|
||
| ```csharp | ||
| class MyType : IReflect | ||
| { | ||
| [DynamicallyAccessedMembers( | ||
| DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.NonPublicFields | | ||
| DynamicallyAccessedMemberTypes.PublicMethods | DynamicallyAccessedMemberTypes.NonPublicMethods | | ||
| DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.NonPublicProperties | | ||
| DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] | ||
| public object InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, | ||
| object?[]? args, ParameterModifier[]? modifiers, CultureInfo? culture, string[]? namedParameters) | ||
| { } | ||
| } | ||
| ``` | ||
|
|
||
| 1. Test reflection scenarios to ensure that the updated annotations capture the intended members and don't introduce run-time errors or warnings. | ||
|
|
||
| For more information on `DynamicallyAccessedMembers` annotations and their usage, see [Prepare .NET libraries for trimming](../../../deploying/trimming/prepare-libraries-for-trimming.md). | ||
|
|
||
| ## Affected APIs | ||
|
|
||
| - <xref:System.Reflection.IReflect.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[])?displayProperty=fullName> | ||
| - <xref:System.Type.FindMembers(System.Reflection.MemberTypes,System.Reflection.BindingFlags,System.Reflection.MemberFilter,System.Object)?displayProperty=fullName> | ||
| - <xref:System.Reflection.TypeInfo.DeclaredMembers?displayProperty=fullName> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.