dotnet / dotnet/winforms

Enable IL2057;IL2062;IL2096 trimmable warnings

Open
#7,464 2 comments 0 reactions 0 assignees View on GitHub
area-Trimming
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

https://github.com/dotnet/winforms/pull/7376/commits/7006bb4884df1d762ba2feb0da14a7824611c1ca (and #7290) suppressed trimmable warnings to enable dependency flow. These warnings should be further investigated.

Suggestions from Jeremy and Vitek:
1. Annotate types that are serialized into resx. Introduce a build-time/design-time tool that that parses resx and generates list of types that should be preserved when trimming is on. In runtime ensure that these types are referenced. That might not be sufficient for report designer/winres.exe type of an application, where a resx file is loaded as a file, not as a .resources file which is linked in.
2. Do not put `RequiresUnreferencedCode` on the internal APIs, otherwise the developer would not be able to handle warning messages. In fact, a more useful messages would explain which types the developer should make "untrimmable" (explicitly referenced). For example, if developer uses an attribute with a string argument which is a type name, Developer should be informed that it's their responsibility to ensure that the named type is not trimmed (is statically discoverable)
3. Example of a good message -https://source.dot.net/#Microsoft.AspNetCore.Http.Extensions/HttpRequestJsonExtensions.cs,22
4. Consider introducing alternative APIs that support trimming
5. In [Com2Properties.cs](https://github.com/dotnet/winforms/blob/0b2ee90e0c1c08458fdebaf72c81f0833e90b8f1/src/System.Windows.Forms/src/System/Windows/Forms/ComponentModel/COM2Interop/COM2Properties.cs) file ` [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]` could be used if an array of hardcoded types is replaced with a method that enumerated these types

Related to #4649

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.