Where are my System.Management.* classes?
I just installed Visual Studio 2010 with .NET Framework 4.0 and C# and I can't find anything un开发者_开发百科der the System.Management
namespace except for System.Management.Instrumentation
. All the online documentation at MSDN about WMI keeps telling me that I have to use classes such as System.Management.ManagementObjectSearcher
or System.Management.ManagementScope
but I don't see those classes.
What happened to those classes and how can I access them?
You need to add a reference to System.Management.dll
to your project.
You can see System.Management.Instrumentation
without adding a reference to System.Management.dll
because it is included in a different library (System.Core.dll
, which is included as a reference automatically), but you cannot access the other types contained by that namespace without explicitly adding a reference to the System.Management.dll
library.
If you're using VS 2010, switch the project to .Net 4.0. Then click on Add References, you will now see System.Management in the list (and not only System.Management.Instrumentation). You can now use the System.Management classes.
I just had the same problem, and that fixed it!
I have netcore and net471 project.
I just downloaded the System.Management as official Microsoft nuget plugin.
Have you added a reference to System.Management
?
This may be due to having set the framework target to "Client Profile". Try switching to the normal "4.0 Framework".
Have you added a reference to System.Management.dll
in your project?
Add a reference to the System.Management.dll
assembly. Both the System.Management.ManagementObjectSearcher
and the System.Management.ManagementScope
types are present in this assembly.
The reason you see the other types is because many types from the namespace System.Management.Instrumentation
are present in System.Core.dll
, which is normally automatically included by Visual Studio as a project reference.
You need to add a reference to System.Management.dll I think.
Find it on your computer > System.Management.dll
Find the .NetFrameWork version that fits your project.
Find the .NetFramework version in the folder name at the end of the search.
Copy the file.
Discard it in the "Bin" folder in your project.
Right click on the references in your project.
Click Add Reference.
Select the file (Project Root > Bin > System.Management.dll).
Project Clean and build.
精彩评论