Skip to content

Document DefaultValueAttribute constructor DynamicallyAccessedMembers removal breaking change for .NET 10 #47921

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
merged 4 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/core/compatibility/10.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
| [Consistent shift behavior in generic math](core-libraries/10.0/generic-math.md) | Behavioral change | Preview 1 |
| [Default trace context propagator updated to W3C standard](core-libraries/10.0/default-trace-context-propagator.md) | Behavioral change | Preview 4 |
| [DriveInfo.DriveFormat returns Linux filesystem types](core-libraries/10.0/driveinfo-driveformat-linux.md) | Behavioral change | Preview 6 |
| [DynamicallyAccessedMembers annotation removed from DefaultValueAttribute ctor](core-libraries/10.0/defaultvalueattribute-dynamically-accessed-members.md) | Binary/source incompatible | Preview 7 |
| [GnuTarEntry and PaxTarEntry no longer includes atime and ctime by default](core-libraries/10.0/tar-atime-ctime-default.md) | Behavioral change | Preview 5 |
| [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 |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "Breaking change: 'DynamicallyAccessedMembers' annotation removed from 'DefaultValueAttribute' ctor"
description: "Learn about the breaking change in .NET 10 where a 'DefaultValueAttribute' constructor is no longer annotated with 'DynamicallyAccessedMembers'."
ms.date: 08/11/2025
ai-usage: ai-assisted
---

# `DynamicallyAccessedMembers` annotation removed from `DefaultValueAttribute` ctor

The <xref:System.ComponentModel.DefaultValueAttribute.%23ctor(System.Type,System.String)?displayProperty=nameWithType> constructor is no longer annotated with <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute>. This constructor is not supported with trimming and throws an exception if reached at run time in a trimmed app.

## Version introduced

.NET 10 Preview 7

## Previous behavior

Previously, if the constructor was used in a trimmed app and the feature switch to disable exception throwing was used, publishing the app generated a trimming warning, and there was a chance the code worked at run time.

## New behavior

Starting in .NET 10, if the constructor is used in a trimmed app and the feature switch to disable exception throwing is used, publishing the app still generates a trimming warning. But there's a smaller chance the code will work at run time.

## Type of breaking change

This change can affect [binary compatibility](../../categories.md#binary-compatibility) and [source compatibility](../../categories.md#source-compatibility).

## Reason for change

This attribute should not be used in trimmed apps because it doesn't reliably work. Trimming should be free to remove type members mentioned in the attribute.

## Recommended action

Don't enable the feature switch that attempts to make <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute> (unreliably) work in trimmed apps.

## Affected APIs

- <xref:System.ComponentModel.DefaultValueAttribute.%23ctor(System.Type,System.String)>
2 changes: 2 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ items:
href: core-libraries/10.0/default-trace-context-propagator.md
- name: DriveInfo.DriveFormat returns Linux filesystem types
href: core-libraries/10.0/driveinfo-driveformat-linux.md
- name: DynamicallyAccessedMembers annotation removed from DefaultValueAttribute ctor
href: core-libraries/10.0/defaultvalueattribute-dynamically-accessed-members.md
- name: GnuTarEntry and PaxTarEntry exclude atime and ctime by default
href: core-libraries/10.0/tar-atime-ctime-default.md
- name: LDAP DirectoryControl parsing is now more stringent
Expand Down