Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
768 views
in Technique[技术] by (71.8m points)

c# - '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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...