4

I created a C# 4.0 Console application. The target framework is .Net Framework 4 Client profile. I want to count the number of cores in my cpu. To do this I created the following class:

internal class MultiThreading
{
    public int GetNumberOfCores()
    {
        var coreCount = 0;
        foreach (var item in new System.Management.ManagementObjectSearcher("Select * from Win32_Processor").Get())
            coreCount += int.Parse(item["NumberOfCores"].ToString());

        return coreCount;
    }
}

For this code to work, it needs a reference to System.Management. To do this in the solution explorer I right clicked my project references->Add reference. A dialog window opens and allows me to select System.Management version 4.0.0.0. The dialog window shows that I am using the 4.0 Framework. So far so good. I click "Add" and I get the following message:

"System.Management, Version 4.0.0.0, Culture=neutral, PublicKeyToken = b034543655555" is incompatible with .Net Framework 4 Client Profile In order to add it you should change >the project's target to a compatible framework first.

As a sanity check I went here: http://msdn.microsoft.com/en-us/library/system.management.managementobjectsearcher.aspx

...and msdn clearly states that System.Management 4.0.0.0 is compatible with .Net Framework 4 Client Profile.

Can anyone assist?

sapbucket
  • 6,795
  • 15
  • 57
  • 94
  • 1
    Hmm, it's maybe possible there is an error on the msdn documentation. Did you try changing your project's target to .NET Framework 4? – Otiel Nov 19 '11 at 21:37
  • @sapbucket - I created a new console project and was able to add it just fine. Is there some other detail that is being missed? – Ritch Melton Nov 19 '11 at 21:50
  • 1
    The PublicKeyToken is wrong, it should be b03f5f7f11d50a3a. No idea how that could happen. – Hans Passant Nov 19 '11 at 23:20
  • It must be a detail that is being missed - just not sure what it is. The public key token is wrong because I typed it in that way (its not a copy/paste). – sapbucket Nov 21 '11 at 03:59
  • I created a new solution and the same issue happened - with the default settings; and it gets worse: all of the System.xxx references generate the same error, not just System.Management. – sapbucket Nov 21 '11 at 04:03

2 Answers2

1

TRy adding it using browse and full path of dll

Taran
  • 2,895
  • 25
  • 22
0

Try changing the Target Framework to .NET Framework 4.

There are differences between Client Profile and the full framework. The Client Profile although runs in framework 4 don´t include all the references to the complete one. And if you target that you are saying that your client will have all the system .dlls referenced in the "References" list. And I guess it´s not true about the System.Management one.

Differences between Microsoft .NET 4.0 full Framework and Client Profile

Community
  • 1
  • 1
Alan Araya
  • 701
  • 1
  • 12
  • 27