runtime: [System.Management] ManagementObjectSearcher throws MarshalDirectiveException
Version: 4.5.0 Platform: .NET Core 3.0 (WPF) app
var wmi = new ManagementObjectSearcher("select * from Win32_OperatingSystem")
.Get()
.Cast<ManagementObject>()
.First();
Then I get this exception:
System.Runtime.InteropServices.MarshalDirectiveException: 'Cannot marshal 'parameter dotnet/corefx#3': Cannot marshal a string by-value with the [Out] attribute.'
The exact issue is in ManagementPath.GetWbemPath:

It could be caused by a “wrong” p/invoke here:
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 35 (21 by maintainers)
Just forked & build a local copy using the latest sources, and that no longer contains the exception! No need to create a PR, but I learned how to fork & build corefx so still lots of added value 👍
@danmosemsft thanks very much for the pointers, yes you are right the dll I used didn’t contain important classes, I should use dll from this folder runtimes\win\lib\netcoreapp2.0 from v4.6.0 nuget package of system.management.
@danmosemsft I’ll take a look!