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 members accessible due ComVisibleAttribute handling #378

Closed
ericstj opened this issue Sep 26, 2018 · 6 comments
Closed

Add members accessible due ComVisibleAttribute handling #378

ericstj opened this issue Sep 26, 2018 · 6 comments
Labels

Comments

@ericstj
Copy link
Member

ericstj commented Sep 26, 2018

See dotnet/corefx#32491

The linker was trimming an internal interface because it didn't see any uses, but it would be used by COM. The managed code passes the object implementing that interface to native code and the native code would QI for the interface. Runtime would return the CCW for the interface but that would be missing the necessary methods and native code AV'ed when calling it.

We should look at a heuristic for identifying these interfaces.

@jkotas suggests looking at the ComImportAttribute: I'm not sure that's sufficient. I think technically any COMVisible interface would fall in this bucket. I believe most interfaces are COMVisible by default, but @luqunl would know better here.

/cc @sbomer @erozenfeld

@luqunl
Copy link

luqunl commented Sep 26, 2018

Members in all [ComImport] types shouldn't be trimmed.
For ComVisible case, members in all public types should not be trimmed --- I guess ILLinker doesn't trim public types' members.

@ericstj
Copy link
Member Author

ericstj commented Sep 26, 2018

I see, thanks for that clarification.

@erozenfeld
Copy link
Member

This is the same issue we encountered in dotnet/corefx#30092 where System.Drawing.Common.Interop/Ole32/IStream (https://github.com/dotnet/corefx/blob/dee434428ee392302ff2050bbee304c9fce68b2f/src/Common/src/Interop/Windows/Ole32/Interop.IStream.cs#L22), which is also [ComImport] had its members trimmed. I opened #338 to track fixing that in the linker but it looks like my fix suggestion there wasn't correct. I'll close that issue and keep this one open.

@erozenfeld
Copy link
Member

For ComVisible case, members in all public types should not be trimmed --- I guess ILLinker doesn't trim public types' members.

ILLink doesn't trim public type members when running with -r option. That's how it's running in corefx. However, it does trim public type members in other configurations. The fix for this issue should include not trimming members in [ComVisible] public types.

@luqunl
Copy link

luqunl commented Sep 27, 2018

The fix for this issue should include not trimming members in [ComVisible] public types.

Yes, Please. CCW scenario need these type members.

@marek-safar marek-safar changed the title Linker should not trim internal interfaces that are visible to COM Add members accessible due ComVisibleAttribute handling Oct 3, 2019
@vitek-karas
Copy link
Member

In .NET 7 the built-in COM is not trim compatible (and probably never will be, it's almost impossible to guarantee correctness statically). So it's disable by default. The recommended solution for making COM usage trimmable is to use ComWrappers. COM through ComWrappers is completely trimmable and supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants