Where are my System.Management.* classes?

折月煮酒 提交于 2019-12-04 16:54:57

问题


I just installed Visual Studio 2010 with .NET Framework 4.0 and C# and I can't find anything under 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?


回答1:


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.




回答2:


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!




回答3:


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".




回答4:


Have you added a reference to System.Management.dll in your project?




回答5:


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.




回答6:


You need to add a reference to System.Management.dll I think.




回答7:


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.



来源:https://stackoverflow.com/questions/4193883/where-are-my-system-management-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!