The type or namespace name 'ManagementEventWatcher' not found

天涯浪子 提交于 2019-12-11 00:45:14

问题


Why do I get The type or namespace name 'ManagementEventWatcher' not found in the following code:

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Management;

class Program {
    public ManagementEventWatcher mgmtWtch;

    static void Main(string[] args)
    {
        InitializeComponent();
        mgmtWtch = new System.Management
                     .ManagementEventWatcher("Select * From Win32_ProcessStartTrace");
        mgmtWtch.EventArrived += new    
            System.Management.EventArrivedEventHandler(mgmtWtch_EventArrived);
        mgmtWtch.Start();
    }
}

I think my dll doesn't have this method, but how to check?


回答1:


Have you added the reference as well as the using? eg

using System.Management;

is not enough.. you need to add the reference to System.Management too.




回答2:


Your Main method is static, but your mgmWtch variable is not. Declare it as as static.



来源:https://stackoverflow.com/questions/6218272/the-type-or-namespace-name-managementeventwatcher-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!