Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to keep/remove COM interfaces #101087

Merged
merged 3 commits into from
Apr 16, 2024
Merged

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Apr 15, 2024

Adds an illink option that can be used to remove COM interfaces (the existing behavior is to preserve COM interfaces on marked types). If a type implements a COM interface that is also marked elsewhere, it will still be kept even with --keep-com-interfaces false. This includes windows runtime interfaces under the same option name.

This eliminates some trim warnings in winforms due to trim-incompatible code in Control's implementations of COM interfaces like IPersistPropertyBag. Experimentally, this still produces a working app for the scenario we've been testing. For now, this just introduces the option without setting it by default anywhere (or exposing it in MSBuild) so that we can opt in from the winforms scenario. We might consider setting it wherever BuiltInComInteropSupport is false.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Apr 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Apr 15, 2024
Copy link
Contributor

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@jkoritzinsky jkoritzinsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have another idea to avoid silent bad RCWs/CCWs: Given that this would break when built-in COM is enabled, could we remove the attributes/metadata that make an interface a COM interface if any of its members are trimmed? Then we wouldn't have the bad scenario where someone could say "don't keep COM interfaces, but keep built-in COM enabled", as if a COM interface is trimmed, it's no longer a COM interface.

@sbomer
Copy link
Member Author

sbomer commented Apr 16, 2024

Thanks for the suggestion, I opened #101128 to track that, but I don't think we need it for this change. The problem you mentioned exists with the current behavior - even when keeping COM interfaces, we may remove interface members. I think we are covered by the fact that built-in COM is not supported when trimming.

@sbomer sbomer merged commit 8262020 into dotnet:main Apr 16, 2024
78 of 80 checks passed
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
Adds an illink option that can be used to remove COM
interfaces (the existing behavior is to preserve COM interfaces
on marked types). If a type implements a COM interface that is
also marked elsewhere, it will still be kept even with
`--keep-com-interfaces false`. This includes windows runtime
interfaces under the same option name.

This eliminates some trim warnings in winforms due to
trim-incompatible code in Control's implementations of COM
interfaces like IPersistPropertyBag. Experimentally, this still
produces a working app for the scenario we've been testing
(https://github.com/dotnet/winforms/tree/main/src/System.Windows.Forms/tests/IntegrationTests/TrimTest).
For now, this just introduces the option without setting it by
default anywhere (or exposing it in MSBuild) so that we can opt
in from the winforms scenario. We might consider setting it
wherever `BuiltInComInteropSupport` is false.
@github-actions github-actions bot locked and limited conversation to collaborators May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants