|
1 | 1 | --- |
2 | | -title: "Breaking change: Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code" |
| 2 | +title: "Breaking change: DynamicallyAccessedMembers annotation removed from trim-unsafe configuration APIs" |
3 | 3 | description: "Learn about the breaking change in .NET 10 where DynamicallyAccessedMembers annotations were removed from trim-unsafe Microsoft.Extensions.Configuration APIs." |
4 | | -ms.date: 12/21/2024 |
| 4 | +ms.date: 07/22/2025 |
5 | 5 | ai-usage: ai-assisted |
6 | 6 | ms.custom: https://github.com/dotnet/docs/issues/47433 |
7 | 7 | --- |
8 | 8 |
|
9 | | -# Removed DynamicallyAccessedMembers annotation from trim-unsafe Microsoft.Extensions.Configuration code |
| 9 | +# DynamicallyAccessedMembers annotation removed from trim-unsafe configuration APIs |
10 | 10 |
|
11 | | -Certain Microsoft.Extensions.Configuration APIs that were marked as <xref:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute> and had <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute> annotations to preserve some necessary members during trimming have had those annotations removed completely. This change affects the trimming behavior of these APIs in .NET 10. |
| 11 | +[Certain APIs](#affected-apis) related to <xref:Microsoft.Extensions.Configuration> that were marked as <xref:System.Diagnostics.CodeAnalysis.RequiresUnreferencedCodeAttribute> were also annotated to preserve at least some of the necessary members when trimming. This made the API partially work when trimming, while still generating trimming warnings. The annotations are now removed completely. Users are encouraged to migrate to the source generator that works reliably with trimming. |
12 | 12 |
|
13 | 13 | ## Version introduced |
14 | 14 |
|
15 | 15 | .NET 10 Preview 6 |
16 | 16 |
|
17 | 17 | ## Previous behavior |
18 | 18 |
|
19 | | -Previously, certain Microsoft.Extensions.Configuration APIs worked with some limited use cases while generating trimming warnings at publish time. These APIs were annotated to preserve at least some of the necessary members when trimming, making the API partially functional in trimmed scenarios. |
| 19 | +Previously, the [affected APIs](#affected-apis) worked with some limited use cases while generating trimming warnings at publish time. These APIs were annotated to preserve at least some of the necessary members when trimming, making the API partially functional in trimmed scenarios. |
20 | 20 |
|
21 | 21 | ## New behavior |
22 | 22 |
|
23 | | -Starting in .NET 10, the same Microsoft.Extensions.Configuration APIs now work with even more limited use cases while still generating trimming warnings at publish time. The <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute> annotations have been completely removed, reducing the amount of code preserved during trimming. |
| 23 | +Starting in .NET 10, the [affected APIs](#affected-apis) now work with even more limited use cases while still generating trimming warnings at publish time. |
24 | 24 |
|
25 | 25 | ## Type of breaking change |
26 | 26 |
|
27 | 27 | This change can affect [binary compatibility](../../categories.md#binary-compatibility). |
28 | 28 |
|
29 | 29 | ## Reason for change |
30 | 30 |
|
31 | | -The annotations were removed as part of an effort to remove uses of <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All> from the product. This change encourages users to migrate to more trim-safe alternatives. |
| 31 | +The annotations were removed as part of an effort to remove uses of <xref:System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.All?displayProperty=nameWithType> from the product. |
32 | 32 |
|
33 | 33 | ## Recommended action |
34 | 34 |
|
35 | 35 | Use the binding configuration source generator, which works reliably with trimming and provides a trim-safe alternative to these APIs. |
36 | 36 |
|
37 | 37 | ## Affected APIs |
38 | 38 |
|
39 | | -Overloads that generate trimming warnings. |
| 39 | +- <xref:Microsoft.Extensions.Configuration.ConfigurationBinder.Get(Microsoft.Extensions.Configuration.IConfiguration,System.Type,System.Action{Microsoft.Extensions.Configuration.BinderOptions})?displayProperty=fullName> |
| 40 | +- <xref:Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue(Microsoft.Extensions.Configuration.IConfiguration,System.Type,System.String)?displayProperty=fullName> |
| 41 | +- <xref:Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue(Microsoft.Extensions.Configuration.IConfiguration,System.Type,System.String,System.Object)?displayProperty=fullName> |
| 42 | +- <xref:Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue``1(Microsoft.Extensions.Configuration.IConfiguration,System.String)?displayProperty=fullName> |
| 43 | +- <xref:Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue``1(Microsoft.Extensions.Configuration.IConfiguration,System.String,``0)?displayProperty=fullName> |
| 44 | +- <xref:Microsoft.Extensions.Configuration.ConfigurationBinder.Get``1(Microsoft.Extensions.Configuration.IConfiguration)?displayProperty=fullName> |
| 45 | +- <xref:Microsoft.Extensions.Configuration.ConfigurationBinder.Get``1(Microsoft.Extensions.Configuration.IConfiguration,System.Action{Microsoft.Extensions.Configuration.BinderOptions})?displayProperty=fullName> |
| 46 | +- <xref:Microsoft.Extensions.Logging.Configuration.LoggerProviderOptions.RegisterProviderOptions``2(Microsoft.Extensions.DependencyInjection.IServiceCollection)?displayProperty=fullName> |
| 47 | +- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsoleFormatter``2(Microsoft.Extensions.Logging.ILoggingBuilder)?displayProperty=fullName> |
| 48 | +- <xref:Microsoft.Extensions.Logging.ConsoleLoggerExtensions.AddConsoleFormatter``2(Microsoft.Extensions.Logging.ILoggingBuilder,System.Action{``1})?displayProperty=fullName> |
| 49 | +- <xref:Microsoft.Extensions.DependencyInjection.OptionsBuilderConfigurationExtensions.BindConfiguration``1(Microsoft.Extensions.Options.OptionsBuilder{``0},System.String,System.Action{Microsoft.Extensions.Configuration.BinderOptions})?displayProperty=fullName> |
| 50 | +- <xref:Microsoft.Extensions.DependencyInjection.OptionsBuilderConfigurationExtensions.Bind``1(Microsoft.Extensions.Options.OptionsBuilder{``0},Microsoft.Extensions.Configuration.IConfiguration)?displayProperty=fullName> |
| 51 | +- <xref:Microsoft.Extensions.DependencyInjection.OptionsBuilderConfigurationExtensions.Bind``1(Microsoft.Extensions.Options.OptionsBuilder{``0},Microsoft.Extensions.Configuration.IConfiguration,System.Action{Microsoft.Extensions.Configuration.BinderOptions})?displayProperty=fullName> |
| 52 | +- <xref:Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure*?displayProperty=fullName> |
| 53 | +- <xref:Microsoft.Extensions.Options.ConfigureFromConfigurationOptions`1?displayProperty=fullName> |
| 54 | +- <xref:Microsoft.Extensions.Options.NamedConfigureFromConfigurationOptions`1?displayProperty=fullName> |
0 commit comments