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

Luca Romagnoli picture Luca Romagnoli · Nov 25, 2009 · Viewed 50.7k times · Source

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

Answer

MoominTroll picture MoominTroll · Nov 25, 2009

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