嗨,我正在使用这个方法获取mac地址
public string GetMACAddress() { System.Management.ManagementClass mc = default(System.Management.ManagementClass); ManagementObject mo = default(ManagementObject); mc = new ManagementClass("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection moc = mc.GetInstances(); foreach (var mo in moc) { if (mo.Item("IPEnabled") == true) { return mo.Item("MacAddress").ToString(); }else return null; } }
但我收到这个错误
Compiler Error Message: CS0234: The type or namespace name 'ManagementClass' does not exist in the namespace 'System.Management' (are you missing an assembly reference?)
我要做什么来解决它?
谢谢
解决方法
您需要在项目中使用
add a reference to System.Management.