Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 21, 2025

Summary

Fixes the trimming annotation on LayoutAttribute.LayoutType property to properly propagate trimming information from the constructor parameter.

Problem

The LayoutAttribute constructor parameter had the [DynamicallyAccessedMembers(Component)] annotation, but the LayoutType property that stores this value did not have the annotation. This caused consumers of the attribute to receive false trimming warnings when accessing the property:

// Constructor parameter is properly annotated
public LayoutAttribute([DynamicallyAccessedMembers(Component)] Type layoutType)
{
    LayoutType = layoutType; // Assignment to property without annotation
    // ...
}

// Property without annotation - causes warnings for consumers
public Type LayoutType { get; private set; }

Solution

Added the [DynamicallyAccessedMembers(Component)] annotation to the LayoutType property to ensure trimming information flows properly:

[DynamicallyAccessedMembers(Component)]
public Type LayoutType { get; private set; }

This ensures that:

  • The trimming analyzer understands that all members of the component type should be preserved
  • Consumers can access LayoutType without false warnings
  • The annotation on the property matches the constructor parameter, maintaining consistency

Testing

  • All 1,174 existing tests in the Components test suite pass
  • Build completes without errors or warnings
  • No security issues detected by CodeQL

Fixes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>[Blazor] LayoutAttribute.LayoutType should have proper trimming annotation</issue_title>
<issue_description>The LayoutAttribute property in Microsoft.AspNetCore.Components.LayoutAttribute should also have [DynamicallyAccessedMembers(Component)] annotation. Currently, only the constructor parameter is annotated, which gives consumers of the attribute a false warning when accessing the property.

public Type LayoutType { get; private set; }

Should be:

[DynamicallyAccessedMembers(Component)]
public Type LayoutType { get; private set; }
```</issue_description>

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

<comments>
</comments>

Fixes #64119


💡 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 AI changed the title [WIP] Add trimming annotation to LayoutAttribute.LayoutType Add DynamicallyAccessedMembers annotation to LayoutAttribute.LayoutType property Oct 21, 2025
Copilot AI requested a review from oroztocil October 21, 2025 13:30
Copilot finished work on behalf of oroztocil October 21, 2025 13:30
@oroztocil oroztocil marked this pull request as ready for review October 22, 2025 08:32
@oroztocil oroztocil requested a review from a team as a code owner October 22, 2025 08:32
Copilot AI review requested due to automatic review settings October 22, 2025 08:32
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 the [DynamicallyAccessedMembers(Component)] annotation to the LayoutAttribute.LayoutType property to properly propagate trimming information from the constructor parameter. This fix prevents false trimming warnings for consumers accessing the property.

  • Adds the missing trimming annotation to the LayoutType property
  • Ensures consistency between constructor parameter and property annotations
  • Resolves false warnings when consumers access the property value

@oroztocil oroztocil enabled auto-merge (squash) October 22, 2025 08:33
@oroztocil oroztocil merged commit 0576690 into main Oct 22, 2025
31 checks passed
@oroztocil oroztocil deleted the copilot/add-trimming-annotation-layouttype branch October 22, 2025 13:27
@dotnet-policy-service dotnet-policy-service bot added this to the 11.0-preview1 milestone Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components Attention: Shared Code Modified

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Blazor] LayoutAttribute.LayoutType should have proper trimming annotation

3 participants