Skip to content

Commit a68703f

Browse files
Copilotgewarren
andauthored
Document DefaultValueAttribute constructor DynamicallyAccessedMembers removal breaking change for .NET 10 (#47921)
* Initial plan * Add breaking change documentation for DefaultValueAttribute DynamicallyAccessedMembers removal Co-authored-by: gewarren <[email protected]> * human edits * placement --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: gewarren <[email protected]>
1 parent dcd9fe8 commit a68703f

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
4242
| [Consistent shift behavior in generic math](core-libraries/10.0/generic-math.md) | Behavioral change | Preview 1 |
4343
| [Default trace context propagator updated to W3C standard](core-libraries/10.0/default-trace-context-propagator.md) | Behavioral change | Preview 4 |
4444
| [DriveInfo.DriveFormat returns Linux filesystem types](core-libraries/10.0/driveinfo-driveformat-linux.md) | Behavioral change | Preview 6 |
45+
| [DynamicallyAccessedMembers annotation removed from DefaultValueAttribute ctor](core-libraries/10.0/defaultvalueattribute-dynamically-accessed-members.md) | Binary/source incompatible | Preview 7 |
4546
| [GnuTarEntry and PaxTarEntry no longer includes atime and ctime by default](core-libraries/10.0/tar-atime-ctime-default.md) | Behavioral change | Preview 5 |
4647
| [LDAP DirectoryControl parsing is now more stringent](core-libraries/10.0/ldap-directorycontrol-parsing.md) | Behavioral change | Preview 1 |
4748
| [MacCatalyst version normalization](core-libraries/10.0/maccatalyst-version-normalization.md) | Behavioral change | Preview 1 |
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: "Breaking change: 'DynamicallyAccessedMembers' annotation removed from 'DefaultValueAttribute' ctor"
3+
description: "Learn about the breaking change in .NET 10 where a 'DefaultValueAttribute' constructor is no longer annotated with 'DynamicallyAccessedMembers'."
4+
ms.date: 08/11/2025
5+
ai-usage: ai-assisted
6+
---
7+
8+
# `DynamicallyAccessedMembers` annotation removed from `DefaultValueAttribute` ctor
9+
10+
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.
11+
12+
## Version introduced
13+
14+
.NET 10 Preview 7
15+
16+
## Previous behavior
17+
18+
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.
19+
20+
## New behavior
21+
22+
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.
23+
24+
## Type of breaking change
25+
26+
This change can affect [binary compatibility](../../categories.md#binary-compatibility) and [source compatibility](../../categories.md#source-compatibility).
27+
28+
## Reason for change
29+
30+
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.
31+
32+
## Recommended action
33+
34+
Don't enable the feature switch that attempts to make <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute> (unreliably) work in trimmed apps.
35+
36+
## Affected APIs
37+
38+
- <xref:System.ComponentModel.DefaultValueAttribute.%23ctor(System.Type,System.String)>

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ items:
4242
href: core-libraries/10.0/default-trace-context-propagator.md
4343
- name: DriveInfo.DriveFormat returns Linux filesystem types
4444
href: core-libraries/10.0/driveinfo-driveformat-linux.md
45+
- name: DynamicallyAccessedMembers annotation removed from DefaultValueAttribute ctor
46+
href: core-libraries/10.0/defaultvalueattribute-dynamically-accessed-members.md
4547
- name: GnuTarEntry and PaxTarEntry exclude atime and ctime by default
4648
href: core-libraries/10.0/tar-atime-ctime-default.md
4749
- name: LDAP DirectoryControl parsing is now more stringent

0 commit comments

Comments
 (0)