C# · 12月 26, 2021

c# – ‘ManagementClass’不存在于命名空间’System.Management’

嗨,我正在使用这个方法获取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.