jemandanders
jemandanders

Reputation: 49

C# system.management is not loaded

I'm trying to use system.management in a C# windows forms app in VS 2017, but it just won't work. Here is a code sample:

using System;
using System.Windows.Forms;
using System.Management;

namespace MyWMIapp
{

    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void okButton_Click(object sender, EventArgs e)
        {

            ManagementScope scope = new ManagementScope(@”\\MyComputerName\root\CIMV2″);

        }
    }
}

At: "using System.Management;" it tells me: this is not needed/used.

At: "ManagementScope scope = ......" it tells me: not found (maybe a missing using-Directive), and is red underlined.

Both is obviously wrong. I'm loading it and I'm using it. Why don't both lines "see" each other?

Upvotes: 2

Views: 2962

Answers (2)

Carsten
Carsten

Reputation: 2201

I had the same issue. Reason was an old nuget source and therefore I could not see all packages. Here the fix:

nuget sources add -source api.nuget.org/v3/index.json -name nuget.org

Upvotes: 0

Cinchoo
Cinchoo

Reputation: 6322

Add reference to System.Management.dll to your project.

Upvotes: 3

Related Questions