tags:

views:

48

answers:

1

Hi all,

I'm trying to write a custom decoupled WMI provider in C#. I've followed the examples and yet whenever I try to access my WMI class from either WMI Studio, through PowerShell, or via wmic, it just hangs there indefinitely until I terminate the provider host app, at which point I get an error ranging from "Invalid Class" to "The remote procedure call failed".

I can see my WMI provider fine if I don't try to actually access an instance of it, so I know it's registering with WMI.

Here's the code I'm running:

    [assembly: WmiConfiguration(@"root\CIMV2", HostingModel=ManagementHostingModel.Decoupled)]
    [RunInstaller(true)]
 public class WmiInstaller : DefaultManagementInstaller { }

    [ManagementEntity(Singleton=true)]
    [ManagementQualifier("Description", Value="Accesses and manipulates licenses held in the SLN license database.")]
 public class SoftwareLicensingNetworkLicenseDatabase {
     [ManagementBind]
     public SoftwareLicensingNetworkLicenseDatabase() { Test = "OMG!"; }

  [ManagementProbe]
  public string Test;
 }

And then in my main function:

    [STAThread]
  static void Main() {

   InstrumentationManager.RegisterType(typeof(SoftwareLicensingNetworkLicenseDatabase));
   Console.ReadLine();

   InstrumentationManager.UnregisterType(typeof(SoftwareLicensingNetworkLicenseDatabase));


  }

I've tried any number of things to diagnose this issue: switch to .Net 3.5 (I'm using .Net 4.0), change namespace names, use a multi-instance class instead of a singleton, etc.

Any help would be sincerely appreciated!

A: 

Nevermind, I figured it out:

Your Main function cannot have STAThread as an attribute. I added it when I was debugging something that required it and had not taken it off. It figures it would take me so long to figure out something so simple and obvious once you think about it.

rakuo15