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

unable to get cpuid by ManagementObjectSearcher #29776

Closed
zhusheping opened this issue Apr 24, 2019 · 6 comments
Closed

unable to get cpuid by ManagementObjectSearcher #29776

zhusheping opened this issue Apr 24, 2019 · 6 comments

Comments

@zhusheping
Copy link

I wan't get cpuid in a console app with core3.0 preview with

           String processorID = "";
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(
                "Select * FROM WIN32_Processor");
            ManagementObjectCollection mObject = searcher.Get();
            foreach (ManagementObject obj in mObject)
            {
                processorID = obj["ProcessorId"].ToString();
            }
            return processorID;

And exception throwed:Cannot marshal 'parameter dotnet/corefx#3': Cannot marshal a string by-value with the [Out] attribute.

@karelz
Copy link
Member

karelz commented Apr 24, 2019

I assume it is System.Management problem? @Anipik can you please help?

@Anipik
Copy link
Contributor

Anipik commented Apr 25, 2019

Yeah i will take a look

@Anipik
Copy link
Contributor

Anipik commented Apr 25, 2019

i tried it with the master branch as well core3.0 preview, i am not able to repro the bug.
Its the printing the processor id as BFEBFBFF000406F1

can you give more context on the failure or about the machine where you are running this code ?

@zhusheping
Copy link
Author

It was throwed when new a ManagementObjectSearcher. The StackTrace :
at System.StubHelpers.StubHelpers.ThrowInteropParamException(Int32 resID, Int32 paramIdx)
at System.Management.ManagementPath.GetWbemPath(IWbemPath wbemPath)
at System.Management.ManagementPath.GetWbemPath()
at System.Management.ManagementPath.get_Path()
at System.Management.ManagementScope.set_prvpath(ManagementPath value)
at System.Management.ManagementScope._Clone(ManagementScope scope, IdentifierChangedEventHandler handler)
at System.Management.ManagementScope._Clone(ManagementScope scope)
at System.Management.ManagementObjectSearcher..ctor(ManagementScope scope, ObjectQuery query, EnumerationOptions options)
at System.Management.ManagementObjectSearcher..ctor(String queryString)
at CustomConfig.HwInfoService.GetMachineCode() in D:\TFlow_Clould\TfrcClould\CustomConfig\HwInfoService.cs:line 20
at CustomConfig.Config..cctor() in D:\TFlow_Clould\TfrcClould\CustomConfig\Config.cs:line 42

And Its the printing the processor id as BFEBFBFF000506E3 in a core 2.1 console app.

I guess it's related to calling unmanaged DLL.

@karelz
Copy link
Member

karelz commented Jun 5, 2019

@Anipik any update?
@zhusheping are you still able to reproduce on latest Preview of 3.0?

@karelz karelz transferred this issue from dotnet/core Jun 5, 2019
@jkotas
Copy link
Member

jkotas commented Jun 5, 2019

This is known issue with .NET Core 3.0 and old version of System.Management package.

For .NET Core 3.0, you need to reference latest preview version 4.6.0-preview5.19224.8 of https://www.nuget.org/packages/System.Management/ to workaround it.

cc @jkoritzinsky

This is duplicate of #29725 and #28840

@jkotas jkotas closed this as completed Jun 5, 2019
@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants