Managed WMI Event class is not an event class???

Posted by galets on Stack Overflow See other posts from Stack Overflow or by galets
Published on 2010-12-31T16:51:15Z Indexed on 2010/12/31 16:53 UTC
Read the original article Hit count: 177

Filed under:
|
|
|

I am using directions from here: http://msdn.microsoft.com/en-us/library/ms257351(VS.80).aspx to create a managed event class. Here's the code that I wrote:

[ManagementEntity]
[InstrumentationClass(InstrumentationType.Event)]
public class MyEvent
{
    [ManagementKey]
    public string ID { get; set; }
    [ManagementEnumerator]
    static public IEnumerable<MyEvent> EnumerateInstances()
    {
        var e = new MyEvent() { ID = "9A3C1B7E-8F3E-4C54-8030-B0169DE922C6" };
        return new MyEvent[] { e };
    }
}

class Program
{
    static void Main(string[] args)
    {
        var thisAssembly = typeof(Program).Assembly;
        var wmi_installer = new AssemblyInstaller(thisAssembly, null);
        wmi_installer.Install(null);
        wmi_installer.Commit(null);

        InstrumentationManager.RegisterAssembly(thisAssembly);

        Console.Write("Press Enter...");
        Console.ReadLine();
        var e = new MyEvent() { ID = "A6144A9E-0667-415B-9903-220652AB7334" };
        Instrumentation.Fire(e);

        Console.Write("Press Enter...");
        Console.ReadLine();
        wmi_installer.Uninstall(null);
    }

}

I can run a program, and it properly installs. Using wbemtest.exe I can browse to the event, and "show mof":

[dynamic: ToInstance, provider("WmiTest, 
      Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")]
class MyEvent
{
    [read, key] string ID;
};

Notice, the class does not inherit from __ExtrinsicEvent, which is weird...

I can also run select * from MyEvent, and get the result. Instrumentation.Fire() also returns no error. However, when I'm trying to subscribe to event using "Notification Query" option, I'm getting 0x80041059

Number: 0x80041059

Facility: WMI

Description: Class is not an event class.

What am I doing wrong, and is there a correct way to create managed WMI event?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about Windows