Skip to content

Add a new feature switch for WinForms trimming #10813

@LakshanF

Description

@LakshanF

Trimming WinForms will require a set of feature switches to be used similar to other feature switches when trimming WinForms applications.

Exploring the trim warnings from the TrimTest project 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.
  • No support for Binding
  • Use ComponentModel in a trim safe way. See the new API proposal
    • 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 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
      • 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions