Skip to content

Linker warning IL2050 doesn't get suppressed by adding RequiresUnreferencedCode #1989

Closed
@joperezr

Description

@joperezr

While resolving the linker warnings for Microsoft.VisualBasic.Core I found an instance of warning IL2050 here:

https://github.com/dotnet/runtime/blob/21dcc7385ea41beffe19913f2c6b765728d5ee48/src/libraries/Microsoft.VisualBasic.Core/src/Microsoft/VisualBasic/Helpers/UnsafeNativeMethods.vb#L31-L36

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions