Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'ManagementClass' does not exist in the namespace 'System.Management'

Hi i'm using this method for get the mac address

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;

    }

} 

but i receive this error

Compiler Error Message: CS0234: The type or namespace name 'ManagementClass' does not exist in the namespace 'System.Management' (are you missing an assembly reference?)

What i have to do for fix it?

thanks

like image 505
Luca Romagnoli Avatar asked Nov 25 '09 16:11

Luca Romagnoli


1 Answers

You need to add a reference to System.Management in your project.

like image 132
MoominTroll Avatar answered Oct 20 '22 01:10

MoominTroll