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:
@GeertvanHorrik would you like to offer a PR? Right now our focus is on other libraries so it might be some time before we could look at this ourselves.
I will do it, but only for the endless credits, fame and joy it will bring!
But jokes aside, I will try to PR and fix this, might be next week. Is there a time limit?
No, but the sooner you do it the sooner you have the fix 馃槈
Please do let us know if you need any help with setup, etc. The materials in the documentation folder in this repo should cover it all. Start with the developer guide.
Have you tried the newest preview version of the System.Management package? When we added that exception, we also updated System.Management to use char arrays instead of strings for those out parameters.
@jkoritzinsky just tried 4.6.0-preview.19073.11, but that seems not to work either. Will double check next week, if it doesn't work, I will fix & PR.
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 馃憤
I learned how to fork & build corefx
@GeertvanHorrik in that case do you have any interest in contributing something else 馃槂 What are your interests?
https://github.com/dotnet/corefx/issues?q=is%3Aopen+is%3Aissue+label%3Aup-for-grabs
Same issue here
@godrose it's fixed in the codebase, it just needs a new release (and thus patience ;-) )
@danmosemsft Great! Can you share the ETA for the preview 4?
I have no idea, I don't work for MS :-)
@geertvanhorrik yeah I figured that out ))
We don't have a date but it shouldn't be too long. Please do post back confirmation it works, when released and you are able.
@danmosemsft Okay
@danmosemsft Same issue.
ManagementObjectSearcher searcher = new ManagementObjectSearcher
("Select * From Win32_Process Where ParentProcessID=" + pid);
@anipik owns this area and can help check your bits contain this change. Is it possible for you to step into it to check? Symbols should be on Microsoft symbol server. What does "dotnet --info" show?
@danmosemsft @Anipik
.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview4-011223
Commit: 118dd862c8
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview4-011223\
Host (useful for support):
Version: 3.0.0-preview4-27615-11
Commit: ee54d4cbd2
.NET Core SDKs installed:
1.0.4 [C:\Program Files\dotnet\sdk]
1.1.0 [C:\Program Files\dotnet\sdk]
2.0.0 [C:\Program Files\dotnet\sdk]
2.0.3 [C:\Program Files\dotnet\sdk]
2.1.2 [C:\Program Files\dotnet\sdk]
2.1.4 [C:\Program Files\dotnet\sdk]
2.1.100 [C:\Program Files\dotnet\sdk]
2.1.101 [C:\Program Files\dotnet\sdk]
2.1.103 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
2.1.200-preview-007517 [C:\Program Files\dotnet\sdk]
2.1.200-preview-007576 [C:\Program Files\dotnet\sdk]
2.1.200-preview-007589 [C:\Program Files\dotnet\sdk]
2.1.200 [C:\Program Files\dotnet\sdk]
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.401 [C:\Program Files\dotnet\sdk]
2.1.402 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.1.503 [C:\Program Files\dotnet\sdk]
2.1.504 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.600-preview-009426 [C:\Program Files\dotnet\sdk]
2.1.600-preview-009472 [C:\Program Files\dotnet\sdk]
2.1.600-preview-009497 [C:\Program Files\dotnet\sdk]
2.1.600 [C:\Program Files\dotnet\sdk]
2.1.602 [C:\Program Files\dotnet\sdk]
2.2.101 [C:\Program Files\dotnet\sdk]
2.2.200-preview-009748 [C:\Program Files\dotnet\sdk]
2.2.200-preview-009804 [C:\Program Files\dotnet\sdk]
2.2.200 [C:\Program Files\dotnet\sdk]
2.2.202 [C:\Program Files\dotnet\sdk]
3.0.100-preview4-011223 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview4-19216-03 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview4-27615-11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview4-27613-28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
OK, and if you check in the debugger, the 3.0 preview 4 binaries are indeed getting loaded? Just want to exclude the obvious stuff.
@danmosemsft
3>C:\Program Files\dotnet\sdk\3.0.100-preview4-011223\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
1>C:\Program Files\dotnet\sdk\3.0.100-preview4-011223\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
4>C:\Program Files\dotnet\sdk\3.0.100-preview4-011223\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
2>C:\Program Files\dotnet\sdk\3.0.100-preview4-011223\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
@danmosemsft Is this covered by a unit test? Because it looks like it's easily reproducible, at least at my machine.
This is covered by unit tests. That鈥檚 how I originally found it and fixed it. That鈥檚 why it鈥檚 weird that you鈥檙e still hitting it. It鈥檚 been fixed in the source here since the preview 3 timeframe (the fix went in before the CoreCLR change that causes the exception was merged).
@jkoritzinsky Some kind of cache thing I guess. Few restarts and re-adding the package did the trick.
It works as expected without throwing the aforementioned exception. Thanks for quick reply!
It works when I built against a .NET Core 3 project preview 4. Make sure that when installing the NuGet package that the previews checkbox is selected. I initially installed version 4.5, which is over a year old, and which throws the exception. The new version gives the correct number of physical cores and does not throw any errors.
Great!
@danmosemsft when will be this shipping to production?
@nicoriff it will be in 3.0 which will is scheduled for release in Sept, see timeline: https://devblogs.microsoft.com/dotnet/introducing-net-5/
I'm now running into this in a WPF .NET Core 3.0 app that includes a .NET Standard 2.0 lib that uses it.
Latest VS RC1 and .NET Core 3 RC.
I think the fix @jkoritzinsky made was 2746a21357470e3da9e3e9222f2da350c9e5dd3a. @zezba9000 for the avoidance of doubt, perhaps you could use a debugger to see where System.Management.dll is getting loaded from, and use ILSPY or similar to check that change is present?
Oops never mind. I just needed to update my CoreFX libs to the RC versions to match up with .NET Core 3 stuff.
Sorry about that.
@zezba9000 no problem, glad it's working!
Incidentally, now you're here, perhaps you'd be interested in considering a contribution? We have 100's of up for grabs issues. Some are new API ("api-approved" label).
https://github.com/dotnet/corefx/issues?q=is%3Aopen+is%3Aissue+label%3Aup-for-grabs
@danmosemsft I'll take a look!
Cool, ping any of us on an issue if you're interested.
Hi, I am using released .net runtime 3.0 and I am still seeing this issue. Can some one clarify where the fix is and how to consume it?
@tqinli can you please use a debugger or by some means find out for certain where your app is loading System.Management.dll from. Then use ILSPY or Reflector or some similar tool to make sure that binary contains 2746a21
@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.
Most helpful comment
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 馃憤