Skip to content

Commit dd76109

Browse files
authored
Add list of recommended replacements for popular reflection-based (#36769)
serializers Better instructions for disabling singlewarn
1 parent f0dc825 commit dd76109

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

docs/core/deploying/trimming/incompatibilities.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@ Automatic [COM marshalling](../../../standard/native-interop/cominterop.md) has
1717

1818
## WPF
1919

20-
The Windows Presentation Foundation (WPF) framework makes substantial use of reflection and some features are heavily reliant on run-time code inspection. In .NET 6, it's not possible for trimming analysis to preserve all necessary code for WPF applications. Unfortunately, almost no WPF apps are runnable after trimming, so trimming support for WPF has been disabled in the .NET 6 SDK.
20+
The Windows Presentation Foundation (WPF) framework makes substantial use of reflection and some features are heavily reliant on run-time code inspection. In .NET 6, it's not possible for trimming analysis to preserve all necessary code for WPF applications. Unfortunately, almost no WPF apps are runnable after trimming, so trimming support for WPF is currently disabled in the .NET SDK. See [WPF is not trim-compatible](https://github.com/dotnet/wpf/issues/3811) issue for progress on enabling trimming for WPF.
2121

2222
## Windows Forms
2323

24-
The Windows Forms framework makes minimal use of reflection, but is heavily reliant on built-in COM marshalling. In .NET 6, it has not yet been converted to use ComWrappers. Unfortunately, almost no Windows Forms apps are runnable without built-in COM marshalling, so trimming support for Windows Forms apps has been disabled in the .NET 6 SDK.
24+
The Windows Forms framework makes minimal use of reflection, but is heavily reliant on built-in COM marshalling. Unfortunately, almost no Windows Forms apps are runnable without built-in COM marshalling, so trimming support for Windows Forms apps is disabled in the .NET SDK currently. See [Make WinForms trim compatible](https://github.com/dotnet/winforms/issues/4649) issue for progress on enabling trimming for Windows Forms.
2525

2626
## Reflection-based serializers
2727

28-
Alternative: Reflection-free serializers, like source-generated [System.Text.Json](../../../standard/serialization/system-text-json/source-generation.md).
28+
Alternative: Reflection-free serializers.
2929

3030
Many uses of reflection can be made trimming-compatible, as described in [Introduction to trim warnings](fixing-warnings.md). However, serializers tend to have very complex uses of reflection. Many of these uses cannot be made analyzable at build time. Unfortunately, the best option is often to rewrite the system to use source generation instead.
3131

32+
Popular reflection-based serializers and their recommended alternatives:
33+
34+
- **Newtonsoft.Json**. Recommended alternative: [source generated System.Text.Json](../../../standard/serialization/system-text-json/source-generation.md)
35+
- **System.Configuration.ConfigurationManager**. Recommended alternative: [source generated Microsoft.Extensions.Configuration](https://github.com/dotnet/runtime/issues/44493)
36+
- **System.Runtime.Serialization.Formatters.Binary.BinaryFormatter** Recommended alternative: [Migrate away from BinaryFormatter serialization due to its security and reliability flaws.](../../compatibility/serialization/7.0/binaryformatter-apis-produce-errors.md#recommended-action)
37+
3238
## Dynamic assembly loading and execution
3339

3440
Trimming and dynamic assembly loading is a common problem for systems that support plugins or extensions, usually through APIs like <xref:System.Reflection.Assembly.LoadFrom(System.String)>. Trimming relies on seeing all assemblies at build time, so it knows which code is used and cannot be trimmed away. Most plugin systems load third-party code dynamically, so it's not possible for the trimmer to identify what code is needed.

docs/core/deploying/trimming/trim-warnings/il2104.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ f1_keywords:
1111

1212
## Cause
1313

14-
The assembly 'assembly' produced trim analysis warnings in the context of the app. This means the assembly has not been fully annotated for trimming. Consider contacting the library author to request they add trim annotations to the library. To see detailed warnings for this assembly, turn off grouped warnings by passing either `--singlewarn-` ILLink command line option to show detailed warnings for all assemblies, or `--singlewarn- "assembly"` to show detailed warnings for that assembly. For more information on annotating libraries for trimming, see [Prepare .NET libraries for trimming](../prepare-libraries-for-trimming.md).
14+
The assembly 'assembly' produced trim analysis warnings in the context of the app. This means the assembly has not been fully annotated for trimming. Consider contacting the library author to request they add trim annotations to the library. To see detailed warnings, turn off grouped warnings by setting [`<TrimmerSingleWarn>false</TrimmerSingleWarn>`](../trimming-options.md#show-detailed-warnings) property in your project file. For more information on annotating libraries for trimming, see [Prepare .NET libraries for trimming](../prepare-libraries-for-trimming.md).

0 commit comments

Comments
 (0)