-
Notifications
You must be signed in to change notification settings - Fork 127
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
Linker warning IL2050 doesn't get suppressed by adding RequiresUnreferencedCode #1989
Comments
I have mixed feeling about having RequiresUnreferencedCode suppress COM warnings. Conceptually, it's similar, but hitting COM codepaths after trimming leads to a lot more sadness than regular RequiresUnreferencedCode (the failure modes might be a lot more inscrutable - including wrong methods being called with wrong calling conventions). It's bad enough to the point that we should consider IL2050 to be an error. I wonder if we can somehow connect this to dotnet/runtime#50500 so that if the app is trimmed with default settings, COM would be disabled and VariantChangeType never reached (therefore never generating a warning). If COM would be opted in manually, it's fine to warn from an implementation detail. |
Aside from Michal's comment which I mostly agree with, @LakshanF - can you please look into somehow tying these warnings into COM feature switch (and maybe turning them into errors by default?) |
Some observations related to the discussion above,
|
Did we try this? Specifically, will the app which has the feature switch turned off actually throw an exception if I try to PInvoke using implicit marshalling of COM interfaces (for example - or VARIANT's). That said, trimmer should still warn in these cases - actually it's even more important since we know it will fail at runtime (by default at least). So these COM warnings should still be produced regardless of the feature switch. I added some tests in #2080 around this to understand the current behavior:
I think we should:
It seems we didn't ship this in 5, so this is not a breaking change. @MichalStrehovsky what do you think? |
If we can make it so that this is only suppressible if COM is disabled, it works for me. I would be wary of being able to suppress COM warnings if COM is enabled and we trim stuff. This is the kind of stuff that comes as a support call to Aaron... Yes, reporting at the callsite sounds like an improvement. |
Ideally if COM is disabled then the warnings are effectively errors since the runtime should consistently throw in that case. If we don't allow to suppress the warnings when COM is enabled then there is literally no workaround, which worries me. So far our approach has been "If you suppress the warning you better know what you're doing" and the failure modes in that case are basically unpredictable. I agree that in case of COM they are especially hard to diagnose, but I don't think it's that different from other cases (for example serialization producing payload with missing data - which doesn't fail anywhere and leads to silent data loss - that one is also very bad and very hard to diagnose). If we think we should not allow people to suppress these warnings, then I think a better approach would be to simply refuse to trim apps with COM enabled - completely. |
Disabling built-in COM seem to trim away code that are implicit marshalling of COM interfaces including related VARIANTs as can be see with this recent test change. Direct COM calls as the related Marshal class code referenced above are trimmed away (i.e. Given that we currently strongly discourage using built-in COM support when trimming, I prefer if we allow developers to suppress warnings as proposed above by Vitek if they still want to use built-in COM support. |
The test change unfortunately doesn't validate what happens if COM is disabled (it effectively skips those tests). I think it would be valuable to adds the negative test cases for those as well (validate that runtime fails/throws as expected). But given the split it makes sense that it's likely already failing. |
I validated that they fail with COM disabled. I will add negative tests to this PR. |
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:
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:
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
The text was updated successfully, but these errors were encountered: