Skip to content

ComActivator causes linker to include code which is not needed in most cases #43604

@vitek-karas

Description

@vitek-karas

CoreCLR ComClassFactory::CreateInstanceFromClassFactory calls into managed Internal.Runtime.InteropServices.LicenseInteropProxy.Create (and some other methods as well). This dependency is hardcoded in the System.Private.CoreLib descriptor and so linker can't ever remove the LicenseInteropProxy.

This type brings in a lot of dependencies (ultimately even BinaryFormatter) which also have some trim analysis warnings.

This functionality should not be needed when COM support is turned off - see COM Feature switch.

Also - this functionality is probably only needed when managed COM activation is used by the project - that is, it can only ever be called if ComActivator was used.

Vast majority of .NET Core projects don't use ComActivator and thus including this code is unnecessary.

What to do about this:

  • Verify that the code in ComClassFactory::CreateInstanceFromClassFactory which calls into LicenseInteropProxy can only be used when ComActivator is also used. If this is not true, then more work is needed to determine what to do.
  • Instead of rooting the LicenseInteropProxy always, make it a dynamic dependency (via DynamicDependencyAttribute) of the ComActivator (the right method on it) and remove it from the CoreLib's ILLink descriptor.
  • Add a trimming test which validates that the LicenseInteropProxy is not present in a normal console hello world (even without any feature switches)
  • Make sure that the code is also hidden behind the COM feature switch (this might be a NOP since ComActivator should be hidden behind the feature switch, but maybe some small pieces will be left-over).

Metadata

Metadata

Assignees

Labels

area-Interop-coreclrsize-reductionIssues impacting final app size primary for size sensitive workloads

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions