Skip to content

Conversation

Copilot
Copy link
Contributor

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

@Copilot 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 Copilot AI requested a review from gewarren October 6, 2025 19:34
Copilot finished work on behalf of gewarren October 6, 2025 19:34
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
2 participants