Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 6, 2025

Summary

This PR adds comprehensive breaking change documentation for .NET 10, documenting the replacement of DynamicallyAccessedMemberTypes.All with more restricted annotations in System.Reflection APIs.

Issue

Closes #48898

Changes

Documentation Added

Created breaking change documentation describing how System.Reflection.IReflect.InvokeMember, System.Type.FindMembers, and System.Reflection.TypeInfo.DeclaredMembers APIs have been updated to use more restricted annotations instead of DynamicallyAccessedMemberTypes.All in .NET 10 Preview 1.

Files Created

  1. docs/core/compatibility/reflection/10.0/ireflect-damt-annotations.md

    • Complete breaking change article with all required sections
    • Explains previous overly permissive behavior and new restricted approach
    • Provides recommended actions for developers implementing IReflect or deriving from TypeInfo
    • Lists all affected APIs with proper xref links
  2. Code Snippets

    • docs/core/compatibility/reflection/10.0/snippets/ireflect-damt-annotations/csharp/MyType.cs - C# example showing required annotations
    • docs/core/compatibility/reflection/10.0/snippets/ireflect-damt-annotations/vb/MyType.vb - Visual Basic equivalent
    • Project files for both snippets (verified to compile with .NET 9 SDK)

Files Modified

  • docs/core/compatibility/10.0.md - Added Reflection section to .NET 10 breaking changes overview
  • docs/core/compatibility/toc.yml - Added new Reflection entry for .NET 10

Example

The documentation includes code examples showing how to implement the required annotations when implementing IReflect:

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)
    {
        throw new NotImplementedException();
    }
    // ... other IReflect members
}

Documentation Guidelines

  • ✅ Follows Microsoft Writing Style Guide
  • ✅ Includes proper AI disclosure (ai-usage: ai-generated)
  • ✅ Uses correct xref syntax for API references
  • ✅ Provides both C# and Visual Basic examples
  • ✅ Links to additional resources on trimming preparation

Testing

  • Both C# and VB code snippets successfully compile with .NET 9 SDK
  • Build artifacts (bin/obj) properly excluded via .gitignore
  • Documentation structure validated and properly integrated into existing .NET 10 breaking changes hierarchy
Original prompt

This section details on the original issue you should resolve

<issue_title>[Breaking change]: Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers</issue_title>
<issue_description>### [Breaking change]: Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers

Description

Starting in .NET 10.0, the System.Reflection APIs InvokeMember, FindMembers, and DeclaredMembers have been updated to use more restricted annotations instead of DAMT.All. This change affects scenarios where developers implement the IReflect interface or derive from System.TypeInfo. The previous use of DAMT.All 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.

This change improves the accuracy of annotations and ensures better compatibility with trimming and reflection scenarios. However, it introduces a breaking change for developers who have implemented IReflect or derived from System.TypeInfo, as they may need to update their annotations to align with the new behavior.

Version

.NET 10.0

Previous behavior

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 cause runtime warnings or unsafe reflection calls.

New behavior

The InvokeMember, FindMembers, and DeclaredMembers APIs now use more restricted annotations, which provide better control over the members captured during reflection. Developers implementing IReflect or deriving from System.TypeInfo must update their annotations to match the new behavior.

Ex:

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)
        { }
}

Type of breaking change

  • Source incompatible: When recompiled using .NET 10.0 or targeting the new runtime, existing source code may require changes to annotations to compile successfully.
  • Behavioral change: Existing binaries might behave differently at runtime due to the updated annotations.

Reason for change

The change was introduced to improve the accuracy of annotations in 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

Developers who implement IReflect or derive from System.TypeInfo should review their code and update annotations to align with the new behavior. Specifically:

  1. Replace DAMT.All annotations with more restricted annotations, such as DynamicallyAccessedMemberTypes.PublicMethods, DynamicallyAccessedMemberTypes.NonPublicMethods, or other appropriate types.
  2. Test reflection scenarios to ensure that the updated annotations capture the intended members and do not introduce runtime errors or warnings.

Feature area

  • Core .NET libraries
  • System.Reflection

Affected APIs

  • System.Reflection.IReflect.InvokeMember
  • System.Reflection.IReflect.FindMembers
  • System.Reflection.TypeInfo.DeclaredMembers

Additional resources

For more information on DynamicallyAccessedMembers annotations and their usage, refer to the Microsoft documentation on trimming and reflection.


Associated WorkItem - 495864</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #48898

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/core/compatibility/10.0.md Breaking changes in .NET 10
docs/core/compatibility/reflection/10/ireflect-damt-annotations.md More restricted annotations on InvokeMember/FindMembers/DeclaredMembers
docs/core/compatibility/toc.yml docs/core/compatibility/toc

Copilot AI changed the title [WIP] [Breaking change]: Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers Add breaking change documentation for DAMT.All replacement in System.Reflection APIs Oct 6, 2025
Copilot AI requested a review from gewarren October 6, 2025 19:34
Copilot finished work on behalf of gewarren October 6, 2025 19:34
@gewarren gewarren marked this pull request as ready for review October 10, 2025 00:15
@gewarren gewarren requested a review from a team as a code owner October 10, 2025 00:16
@gewarren gewarren requested review from agocke and Copilot October 10, 2025 00:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive breaking change documentation for .NET 10, documenting the replacement of DynamicallyAccessedMemberTypes.All with more restricted annotations in System.Reflection APIs. The change affects developers implementing IReflect or deriving from TypeInfo classes.

Key changes include:

  • Creation of complete breaking change documentation explaining the annotation restrictions
  • Addition of code examples showing required implementation updates
  • Integration into the .NET 10 breaking changes documentation hierarchy

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
docs/core/compatibility/toc.yml Added new Reflection section entry for .NET 10 breaking changes
docs/core/compatibility/reflection/10.0/ireflect-damt-annotations.md Complete breaking change article with examples and guidance
docs/core/compatibility/10.0.md Added Reflection section to .NET 10 breaking changes overview

@gewarren gewarren enabled auto-merge (squash) October 10, 2025 00:37
@gewarren gewarren closed this Nov 6, 2025
auto-merge was automatically disabled November 6, 2025 18:27

Pull request was closed

@gewarren gewarren reopened this Nov 6, 2025
@gewarren gewarren requested a review from sbomer November 10, 2025 18:14
@gewarren gewarren enabled auto-merge (squash) November 14, 2025 19:48
@gewarren gewarren merged commit 30dfb47 into main Nov 14, 2025
18 checks passed
@gewarren gewarren deleted the copilot/fix-bfc60c08-b60c-4054-9c4d-c84296ad7fae branch November 14, 2025 19:55
@agocke
Copy link
Member

agocke commented Nov 20, 2025

(belated) LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Breaking change]: Replace DAMT.All with more restricted annotation on InvokeMember/FindMembers/DeclaredMembers

4 participants