dotnet / dotnet/winforms

Add a new feature switch for WinForms trimming

Open
#10,813 0 comments 6 reactions 1 assignee Claimed by @LakshanF View on GitHub
area-Trimming
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
1d 13m
Merged PRs (30d)
85

Description

Trimming WinForms will require a set of [feature switches](https://github.com/dotnet/designs/blob/main/accepted/2020/feature-switch.md) to be used similar to [other feature switches](https://github.com/dotnet/runtime/blob/main/docs/workflow/trimming/feature-switches.md) when trimming WinForms applications.

Exploring the trim warnings from the [TrimTest project](https://github.com/dotnet/winforms/blob/main/src/System.Windows.Forms/tests/IntegrationTests/TrimTest/TrimTest.csproj) shows the following areas where having a feature switch(es) could help:
- Not to use WPF assemblies (assume UseWPF `property` is set to false).
- Separate design time (where trimming is not required) and runtime experiences. Design time experience should be able to leverage trim incompatible capabilities like reflection and the publishing experience for trimmed applications should not generate trim warnings for the code that is only leveraged only at design time.
- [System.ComponentModel.Design.IDesignerHost.IsSupported](https://github.com/dotnet/runtime/pull/99647)
- `System.Drawing.Design.UITypeEditor.IsSupported`
- `System.Windows.Forms.Control.AreDesignTimeFeaturesSupported`
- `System.ComponentModel.DefaultValueAttribute.IsSupported`
- No support for Binding
- [System.Windows.Forms.Binding.IsSupported](https://github.com/dotnet/winforms/pull/11023)
- Use `ComponentModel` in a trim safe way. See the new [API proposal](https://github.com/dotnet/runtime/issues/101202)
- `System.Windows.Forms.Primitives.TypeConverterHelper.UseComponentModelRegisteredTypes`
- Used in `System.Windows.Forms.Primitives` assembly
- `System.Windows.Forms.Control.UseComponentModelRegisteredTypes`
- No support for advanced control usage
- ActiveX: `System.Windows.Forms.ActiveXImpl.IsSupported`
- MdiWindowDialog: `System.Windows.Forms.MdiWindowDialog.IsSupported`
- ImageIndexConverter: `System.Windows.Forms.ImageIndexConverter.IsSupported`
- The vast majority of the trim warnings are actually not hit by simple WinForms applications like the TrimTest project. However, the following areas are unlikely to be supported in trimming
- Resource usage that require `BinaryFormatter`
- System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization
- Its very likely the type extension mechanism offered by WinForms need to be curtailed with a feature switch for trimming. For example, [ICustomTypeDescriptor ](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.icustomtypedescriptor) likely need to be restricted and code paths that use this interface will need to be removed via the feature switch.
[Default_Trimmed_Warnings_wpf_attributes_excluded_ComponentModel_ICustomTypeDescriptor.txt](https://github.com/dotnet/winforms/files/14145862/Default_Trimmed_Warnings_wpf_attributes_excluded_ComponentModel_ICustomTypeDescriptor.txt)
- `System.ComponentModel.TypeDescriptor.SupportsInstanceBasedDescriptors`
- `System.ComponentModel.TypeDescriptor.IsComObjectDescriptorSupported`
- Using Nullable Converter
- `System.ComponentModel.NullableConverter.IsSupported`
- Remove the current WinForms trimming prevention block when this feature switch is set.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.