<p>I've created a seperate assembly with a class that is intended to be 
published through wmi.  Then I've created a windows forms app that 
references that assembly and attempts to publish the class. When I try to 
publish the class, I get an exception of type 
System.Management.Instrumentation.WmiProviderInstallationException. The 
message of the exception says "Exception of type 
'System.Management.Instrumentation.WMIInfraException' was thrown.".  I have 
no idea what this means.  I've tried .Net2.0 and .Net3.5 (sp1 too) and get the same results.</p>

<p>Below is my wmi class, followed by the code I used to publish it.</p>

<pre><code>//Interface.cs in assembly WMI.Interface.dll

using System;
using System.Collections.Generic;
using System.Text;

[assembly: System.Management.Instrumentation.WmiConfiguration(@"root\Test",
    HostingModel = 
System.Management.Instrumentation.ManagementHostingModel.Decoupled)]

namespace WMI
{
    [System.ComponentModel.RunInstaller(true)]
    public class MyApplicationManagementInstaller :
        System.Management.Instrumentation.DefaultManagementInstaller { }

    [System.Management.Instrumentation.ManagementEntity(Singleton = true)]
    [System.Management.Instrumentation.ManagementQualifier("Description",
        Value = "Obtain processor information.")]
    public class Interface
    {
        [System.Management.Instrumentation.ManagementBind]
        public Interface()
        {
        }

        [System.Management.Instrumentation.ManagementProbe]
        [System.Management.Instrumentation.ManagementQualifier("Descriiption",
            Value="The number of processors.")]
        public int ProcessorCount
        {
            get { return Environment.ProcessorCount; }
        }
    }
}
</code></pre>

<p><BR/></p>

<pre><code>//Button click in windows forms application to publish class
try
{
    System.Management.Instrumentation.InstrumentationManager.Publish(new 
WMI.Interface());
}
catch (System.Management.Instrumentation.InstrumentationException 
exInstrumentation)
{
    MessageBox.Show(exInstrumentation.ToString());
}
catch (System.Management.Instrumentation.WmiProviderInstallationException 
exProvider)
{
    MessageBox.Show(exProvider.ToString());
}
catch (Exception exPublish)
{
    MessageBox.Show(exPublish.ToString());
}
</code></pre>

[{'answer_id': 69618, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': True, 'text': "<p>I used gacutil - installutil to to test your class (as a dll). The gacutil part worked, but installutil (actually mofcomp) complained about a syntax error:</p>\n\n<p>...</p>\n\n<p>error SYNTAX 0X80044014:\nUnexpected character in class name (must be an identifier)</p>\n\n<p>Compiler returned error 0x80044014</p>\n\n<p>...</p>\n\n<p>So I changed the class name to 'MyInterface' the installutil part worked, but the class didn't return any instances. Finally I changed the hosting model to Network Service and got it to work.</p>\n"}, {'answer_id': 97083, 'author': 'Jeremy', 'author_id': 9266, 'author_profile': 'https://Stackoverflow.com/users/9266', 'pm_score': 2, 'selected': False, 'text': '<p>To summarize, this is the final code that works:</p>\n\n<p>Provider class, in it\'s own assembly:</p>\n\n<pre><code>// the namespace used for publishing the WMI classes and object instances \n[assembly: Instrumented("root/mytest")]\n\nusing System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Management;\nusing System.Management.Instrumentation;\nusing System.Configuration.Install;\nusing System.ComponentModel;\n\nnamespace WMITest\n{\n\n    [InstrumentationClass(System.Management.Instrumentation.InstrumentationType.Instance)] \n    //[ManagementEntity()]\n    //[ManagementQualifier("Description",Value = "Obtain processor information.")]\n    public class MyWMIInterface\n    {\n        //[System.Management.Instrumentation.ManagementBind]\n        public MyWMIInterface()\n        {\n        }\n\n        //[ManagementProbe]\n        //[ManagementQualifier("Descriiption", Value="The number of processors.")]\n        public int ProcessorCount\n        {\n            get { return Environment.ProcessorCount; }\n        }\n    }\n\n    /// &lt;summary&gt;\n    /// This class provides static methods to publish messages to WMI\n    /// &lt;/summary&gt;\n    public static class InstrumentationProvider\n    {\n        /// &lt;summary&gt;\n        /// publishes a message to the WMI repository\n        /// &lt;/summary&gt;\n        /// &lt;param name="MessageText"&gt;the message text&lt;/param&gt;\n        /// &lt;param name="Type"&gt;the message type&lt;/param&gt;\n        public static MyWMIInterface Publish()\n        {\n            // create a new message\n            MyWMIInterface pInterface = new MyWMIInterface();\n\n            Instrumentation.Publish(pInterface);\n\n            return pInterface;\n        }\n\n        /// &lt;summary&gt;\n        /// revoke a previously published message from the WMI repository\n        /// &lt;/summary&gt;\n        /// &lt;param name="Message"&gt;the message to revoke&lt;/param&gt;\n        public static void Revoke(MyWMIInterface pInterface)\n        {\n            Instrumentation.Revoke(pInterface);\n        }        \n    }\n\n    /// &lt;summary&gt;\n    /// Installer class which will publish the InfoMessage to the WMI schema\n    /// (the assembly attribute Instrumented defines the namespace this\n    /// class gets published too\n    /// &lt;/summary&gt;\n    [RunInstaller(true)]\n    public class WMITestManagementInstaller :\n        DefaultManagementProjectInstaller\n    {\n    }\n}\n</code></pre>\n\n<p>Windows forms application main form, publishes provider class:</p>\n\n<pre><code>using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Data;\nusing System.Drawing;\nusing System.Text;\nusing System.Windows.Forms;\nusing System.Management;\nusing System.Management.Instrumentation;\n\nnamespace WMI\n{\n    public partial class Form1 : Form\n    {\n        public Form1()\n        {\n            InitializeComponent();\n        }\n\n        WMITest.MyWMIInterface pIntf_m;\n\n        private void btnPublish_Click(object sender, EventArgs e)\n        {\n            try\n            {\n                pIntf_m = WMITest.InstrumentationProvider.Publish();\n            }\n            catch (ManagementException exManagement)\n            {\n                MessageBox.Show(exManagement.ToString());\n            }\n            catch (Exception exPublish)\n            {\n                MessageBox.Show(exPublish.ToString());\n            }\n        }\n    }\n}\n</code></pre>\n\n<p>Test web application, consumer:</p>\n\n<pre><code>using System;\nusing System.Data;\nusing System.Configuration;\nusing System.Web;\nusing System.Web.Security;\nusing System.Web.UI;\nusing System.Web.UI.WebControls;\nusing System.Web.UI.WebControls.WebParts;\nusing System.Web.UI.HtmlControls;\nusing System.Management.Instrumentation;\nusing System.Management;\n\npublic partial class _Default : System.Web.UI.Page \n{\n    protected void Page_Load(object sender, EventArgs e)\n    {\n        if (!IsPostBack)\n        {\n            ManagementClass pWMIClass = null;\n\n            pWMIClass = new ManagementClass(@"root\\interiorhealth:MyWMIInterface");\n\n            lblOutput.Text = "ClassName: " + pWMIClass.ClassPath.ClassName + "&lt;BR/&gt;" +\n                 "IsClass: " + pWMIClass.ClassPath.IsClass + "&lt;BR/&gt;" +\n                 "IsInstance: " + pWMIClass.ClassPath.IsInstance + "&lt;BR/&gt;" +\n                 "IsSingleton: " + pWMIClass.ClassPath.IsSingleton + "&lt;BR/&gt;" +\n                 "Namespace Path: " + pWMIClass.ClassPath.NamespacePath + "&lt;BR/&gt;" +\n                 "Path: " + pWMIClass.ClassPath.Path + "&lt;BR/&gt;" +\n                 "Relative Path: " + pWMIClass.ClassPath.RelativePath + "&lt;BR/&gt;" +\n                 "Server: " + pWMIClass.ClassPath.Server + "&lt;BR/&gt;";\n\n            //GridView control\n            this.gvProperties.DataSource = pWMIClass.Properties;\n            this.gvProperties.DataBind();\n\n            //GridView control\n            this.gvSystemProperties.DataSource = pWMIClass.SystemProperties;\n            this.gvSystemProperties.DataBind();\n\n            //GridView control\n            this.gvDerivation.DataSource = pWMIClass.Derivation;\n            this.gvDerivation.DataBind();\n\n            //GridView control\n            this.gvMethods.DataSource = pWMIClass.Methods;\n            this.gvMethods.DataBind();\n\n            //GridView control\n            this.gvQualifiers.DataSource = pWMIClass.Qualifiers;\n            this.gvQualifiers.DataBind();\n        }\n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/65364', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9266/']