Skip to content
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

System.Management.WbemDefPath doesn't work with trimming #61960

Open
Symbai opened this issue Nov 23, 2021 · 9 comments
Open

System.Management.WbemDefPath doesn't work with trimming #61960

Symbai opened this issue Nov 23, 2021 · 9 comments
Labels
area-System.Management linkable-framework Issues associated with delivering a linker friendly framework
Milestone

Comments

@Symbai
Copy link

Symbai commented Nov 23, 2021

Description

NativeAOT (the trimming?) breaks the body of System.Management.WbemDefPath..ctor():

 ---> System.InvalidProgramException: Common Language Runtime detected an invalid program. The body of method 'Void System.Management.WbemDefPath..ctor()' is invalid.
   at Internal.Runtime.TypeLoaderExceptionHelper.CreateInvalidProgramException(ExceptionStringID, String) + 0x40
   at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowInvalidProgramExceptionWithArgument(ExceptionStringID, String) + 0x9
   at System.Management.WbemDefPath..ctor() + 0x15

I'm reporting this here since NativeAOT will be moved into this repo anyway and it's probably a trimming issue? in which case it belongs to this repo.

Reproduction Steps

In nativeAOT project:

ManagementClass managementClass = new ManagementClass("Win32_BaseBoard");
var instances = managementClass.GetInstances();
foreach (var obj in instances)
{
    //...
}

In C# project call the export function of the nativeAOT project which executes the code above.

Expected behavior

No exception

Actual behavior

Exception

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

It's a windows x64 DLL project publishing using /p:NativeLib=Shared, I'm using NativeAOT compiler nuget version 6.0.0-*

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Management untriaged New issue has not been triaged by the area owner labels Nov 23, 2021
@hez2010
Copy link
Contributor

hez2010 commented Nov 23, 2021

NativeAOT compiler 6.0.0-* is out-of-date and missing plenty of fixes, can you try again with 7.0.0-*?

@MichalStrehovsky
Copy link
Member

MichalStrehovsky commented Nov 23, 2021

WbemDefPath is built-in COM. This doesn't work with trimming in general and NativeAOT implies trimming. It will have to be converted to ComWrappers.

@MichalStrehovsky MichalStrehovsky added the linkable-framework Issues associated with delivering a linker friendly framework label Nov 23, 2021
@ghost
Copy link

ghost commented Nov 23, 2021

Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

NativeAOT (the trimming?) breaks the body of System.Management.WbemDefPath..ctor():

 ---> System.InvalidProgramException: Common Language Runtime detected an invalid program. The body of method 'Void System.Management.WbemDefPath..ctor()' is invalid.
   at Internal.Runtime.TypeLoaderExceptionHelper.CreateInvalidProgramException(ExceptionStringID, String) + 0x40
   at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowInvalidProgramExceptionWithArgument(ExceptionStringID, String) + 0x9
   at System.Management.WbemDefPath..ctor() + 0x15

I'm reporting this here since NativeAOT will be moved into this repo anyway and it's probably a trimming issue? in which case it belongs to this repo.

Reproduction Steps

In nativeAOT project:

ManagementClass managementClass = new ManagementClass("Win32_BaseBoard");
var instances = managementClass.GetInstances();
foreach (var obj in instances)
{
    //...
}

In C# project call the export function of the nativeAOT project which executes the code above.

Expected behavior

No exception

Actual behavior

Exception

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

It's a windows x64 DLL project publishing using /p:NativeLib=Shared, I'm using NativeAOT compiler nuget version 6.0.0-*

Author: Symbai
Assignees: -
Labels:

area-System.Management, untriaged, linkable-framework

Milestone: -

@Symbai
Copy link
Author

Symbai commented Nov 23, 2021

NativeAOT compiler 6.0.0-* is out-of-date and missing plenty of fixes, can you try again with 7.0.0-*?

Unfortunately not, see dotnet/runtimelab#1748

@MichalStrehovsky MichalStrehovsky changed the title [NativeAOT] Breaks constructor of System.Management.WbemDefPath System.Management.WbemDefPath doesn't work with trimming Nov 24, 2021
@eerhardt
Copy link
Member

If anyone is looking to pick this up and needs an example of how to convert to COMWrappers, here are the PRs that converted System.Drawing.Common to use COMWrappers. They may be useful to get started on how to do it.

#54636
#54884

Also, check out the docs here: https://docs.microsoft.com/en-us/dotnet/standard/native-interop/tutorial-comwrappers

@ViktorHofer ViktorHofer added this to the 8.0.0 milestone Jul 19, 2022
@ViktorHofer ViktorHofer removed the untriaged New issue has not been triaged by the area owner label Jul 19, 2022
@ivanjx
Copy link

ivanjx commented Nov 16, 2022

are there any workarounds on how to make system.management to work with nativeaot for now?

@MichalStrehovsky
Copy link
Member

It's the same problem as #78038 that was recently closed but had a couple other people. System.Management needs to be converted to ComWrappers. It's starting to be a pretty popular request. Cc @jkoritzinsky if this is something that could be addressed with the COM source generator for .NET 8.

@ivanjx
Copy link

ivanjx commented Nov 16, 2022

i managed to workaround using powershell.exe with Get-WmiObject command but indeed being able to do more advanced querying and not needing to parse the text output manually is preferred.

@brandon3343
Copy link

@ivanjx You can try WmiLight, It works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Management linkable-framework Issues associated with delivering a linker friendly framework
Projects
None yet
Development

No branches or pull requests

9 participants