The unusedinterfaces
optimization controls whether or not trimming may remove the interfaceimpl
annotation which denotes whether a class implements an interface. When the optimization is off, the ILLink tool will not remove the annotations regardless of the visibility of the interface (even private interface implementations will be kept). However, unused methods from interfaces may still be removed, as well as .override
directives from methods that implement an interface method. When the optimization is on and the ILLink tool can provably determine that an interface will not be used on a type, the annotation will be removed. In order to know whether it is safe to remove an interface implementation, it is necessary to have a "global" view of the code. In other words, if an assembly is passed without selecting link
for the action
option for ILLink, all classes that implement interfaces from that assembly will keep those interface implementation annotations. For example, if you implement System.IFormattable
from the System.Runtime
assembly, but pass the assembly with --action copy System.Runtime
, the interface implementation will be kept even if your code doesn't use it.