-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
MissingMethodException raised from System.Management.WmiNetUtilsHelper during wmi call (.NET6 self-contained) #78038
Comments
Thanks for reporting. Do you have a small console app where we can repro the issue? |
Reached out to @wzm199309 via Teams (works for the SqlServer team). The exception message is saying that the type that does not have a default parameterless constructor is this one: runtime/src/libraries/System.Management/src/System/Management/InteropClasses/WMIInterop.cs Lines 1176 to 1182 in 57bfe47
It's been like that since it was added to .NET Core 1.0, and in fact it was brought here unmodified from .NET Framework: The exception is thrown here: runtime/src/coreclr/System.Private.CoreLib/src/System/RuntimeType.ActivatorCache.cs Lines 47 to 49 in 57bfe47
The type is being passed via runtime/src/libraries/System.Management/src/System/Management/ManagementPath.cs Lines 248 to 250 in 9d6396d
Which means that from the shared callstack, the exception came from the runtime/src/libraries/System.Management/src/System/Management/ManagementPath.cs Lines 190 to 193 in 9d6396d
@wzm199309 said that this problem is reproing when adding I found a very similar issue opened last year, where trimming an app would cause this exact same exception to show up (although not exactly from @wzm199309 confirmed some of the related projects are trimmed, but not exactly this one throwing the exception. He will disable trimming and try to repro the issue again. In the meanwhile: @eerhardt @AaronRobinsonMSFT do you know if COM and trimming don't play well together? |
They do not. Trimming and COM are incompatible. When an application is trimmed, COM will most likely break because the trimmer is unable to recognize that COM interfaces shouldn't be torn apart. If the trimmer treated interfaces marked as /cc @agocke @vitek-karas |
They don't. You need to use COM Wrappers in order to make COM usage "trim compatible". I don't see the original post saying they are using trimming though. |
@wzm199309 If you are using trimming, you should be getting trim analysis warnings if things are incompatible. Did this show up in that list? |
I asked that information via chat, after I found the related issue #49062. @wzm199309 can give more details on how they are using trimming. |
thanks for help, yes we are using trimming at some of our projects (though dont apply it at one which now having the issue) |
This is confusing to me. The default value for So if your project where it fails doesn't specify |
@vitek-karas Story is this:
|
An even better approach would be to contribute the COM Wrapper changes to https://github.com/dotnet/runtime/tree/main/src/libraries/System.Management to make that library trim-compatible for everyone. I believe it is possible to make your app work with |
@eerhardt thanks for helping, quick questions: 1) do I need to add all COM wrapper classes to sys.management make it enable trim-compatible? 2) by applying DynamicDependencyAttributes you mean I should apply it for all methods calling WMI like [DynamicDependency(DynamicallyAccessedMemberTypes.All, "System.Mangement", "System.Mangement.dll")] |
The current list of warnings in System.Management are located here:
To make System.Management trim compatible, those warnings would need to be addressed.
Here's an example of trying to do this approach, but it was abandoned and never merged: See the discussion at #75176 (comment) for why it was abandoned. You would apply attributes like that in your application where it is using System.Management. |
thanks folks for detailed explanations and suggestions. I will try with manual trimming way first then try enabling COM wrapper with trim-abilities. |
Do you have any guidance available on how precisely to do that? With |
https://learn.microsoft.com/en-us/dotnet/standard/native-interop/com-wrappers is the docs on COM Wrappers. You can see an example of doing this for System.Drawing in these 2 PRs: |
@eerhardt wow, that looks like a lot of work just to be able to use I think I'll see what I can get from the Windows Registry (and possibly SMBIOS) instead! |
Description
SQL IaaS team and are now working on project migration to .NET6, here is an issue we identified with System.Management.WmiNetUtilsHelper during testing which seems to be a known issue, want to seek insights to see how we can resolve it:
Reproduction Steps
Code example:
Expected behavior
WMI call should works
Actual behavior
instead, raising exception
Regression?
No response
Known Workarounds
No response
Configuration
.NET6, windows server 2019, x64
Other information
No response
The text was updated successfully, but these errors were encountered: