Runtime: unable to get cpuid by ManagementObjectSearcher

Created on 24 Apr 2019  路  6Comments  路  Source: dotnet/runtime

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

c# 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.

area-System.Management

Most helpful comment

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 dotnet/runtime#29725 and dotnet/runtime#28840

All 6 comments

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

Yeah i will take a look

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 ?

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.

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

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 dotnet/runtime#29725 and dotnet/runtime#28840

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Timovzl picture Timovzl  路  3Comments

yahorsi picture yahorsi  路  3Comments

aggieben picture aggieben  路  3Comments

jzabroski picture jzabroski  路  3Comments

chunseoklee picture chunseoklee  路  3Comments