Can’t create an instance of a managed WMI provider

Current Status
Solved

Problem
Using the .NET WMI provider extensions 2.0, I cannot create an instance of my custom provider class.

Windows Management Interface (WMI) is a way to expose management and configuration components from your application to scripting and operations tools, like SMS and MOM. In the past, creating a WMI provider required the use of COM. The WMI provider extensions for .NET created the ability to expose read-only management objects. In .NET 3.5, this capability was enhanced to allow for writing properties and calling methods.

Using these extensions, I created a management class for my application. I am having trouble creating instances of this class from the WMI command line, or any of the other WMI tools that I've tried.

Here's the class:

using System.Management.Instrumentation;

namespace ConsoleDecoupled
{
    [ManagementEntity]
    public class Activity
    {
        private string _name;

        [ManagementBind]
        public Activity(string Name)
        {
            _name = Name;
        }

        [ManagementKey]
        public string Name
        {
            get { return _name; }
        }
    }
}


Here's the program that publishes the class to WMI:

using System;
using System.Management.Instrumentation;

namespace ConsoleDecoupled
{
    class Program
    {
        static void Main(string[] args)
        {
            //InstrumentationManager.RegisterType(typeof(Activity));

            Activity instance = new Activity("foo");
            InstrumentationManager.Publish(instance);

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();

            InstrumentationManager.Revoke(instance);
            //InstrumentationManager.UnregisterType(typeof(Activity));
        }
    }
}


And here's what wmic does when I try to create an instance:

wmic:root\cli>path Activity create Name="fee"
Create instance of 'Activity' class (Y/N)?y
ERROR:
Code = 0x80041002
Description = Not found
Facility = WMI


I know that the class is found, because I can query for the instance that I created programmatically:

wmic:root\cli>path Activity where Name="foo"
Name
foo


My next plan of attack is to go through this article on Writing coupled WMI providers, and seeing if I run into similar problems.

Leave a Reply

You must be logged in to post a comment.