Closed
Description
While resolving the linker warnings for Microsoft.VisualBasic.Core I found an instance of warning IL2050 here:
The Linker shows the following message:
Microsoft.VisualBasic.CompilerServices.UnsafeNativeMethods.VariantChangeType(Object&,Object&,Int16,Int16): P/invoke method 'Microsoft.VisualBasic.CompilerServices.UnsafeNativeMethods.VariantChangeType(Object&,Object&,Int16,Int16)' declares a parameter with COM marshalling. Correctness of COM interop cannot be guaranteed after trimming. Interfaces and interface members might be removed.
While the warning makes sense, I was surprised that this warning wouldn't be automatically suppressed by adding RequiresUnreferencedCode attribute on that method. In my mind, when resolving Linker warnings there are pretty much 3 different actions to take:
- Rewrite the statement to make it safe so that the linker won't warn.
- Manually Suppress the error with UnconditionallySuppressMessage (maybe along with adding DynamicDependency when appropriate) if the callsite is deemed safe and the linker is warning as a false positive.
- Add RequiresUnreferencedCode attribute so that you can bubble up the warning to your callers.
For IL2050, there doesn't seem to be a way of doing that 3rd action, which there should be one in my opinion (either via RequiresUnreferencedCode or a new attribute).
cc: @MichalStrehovsky @eerhardt @LakshanF @vitek-karas @sbomer