This article lists patterns that are incompatible with trimming with the current tooling.
Reflection-based serializersAlternative: Reflection-free serializers.
Many uses of reflection can be made trimming-compatible, as described in Introduction to trim warnings. However, serializers tend to have complex uses of reflection. Many of these uses can't be made analyzable at build time. Unfortunately, the best option is often to rewrite the system to use source generation.
The following table lists popular reflection-based serializers and their recommended alternatives:
Runtime code generation via JITRuntime code generation via JIT, for example, via System.Reflection.Emit is incompatible with trimming.
Dynamic assembly loading and executionTrimming and dynamic assembly loading is a common problem for systems that support plugins or extensions, usually through APIs like LoadFrom(String). Trimming relies on seeing all assemblies at build time, so it knows which code is used and can't 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.
Windows platform incompatibilitiesThe following sections list known incompatibilities with trimming on Windows.
NET programming with C++/CLINET programming with C++/CLI currently doesn't support trimming.
Built-in COM marshallingAlternative: COM Wrappers
Automatic COM marshalling has been built in to .NET since .NET Framework 1.0. It uses run-time code analysis to automatically convert between native COM objects and managed .NET objects. Unfortunately, trimming analysis can't always predict what .NET code needs to be preserved for automatic COM marshalling. However, if COM Wrappers are used instead, trimming analysis can guarantee that all used code will be correctly preserved.
WPFThe Windows Presentation Foundation (WPF) framework makes substantial use of reflection and some features are heavily reliant on run-time code inspection. 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 issue for progress on enabling trimming for WPF.
Windows FormsThe 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 issue for progress on enabling trimming for Windows Forms.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4