Unable to cast COM object of type 'System.__ComObject' with STAThread attribute
<p>I wrote a Windows Service that use Firewall COM library <code>Interop.NetFwTypeLib</code> to manage rules for TCP transmission. Deployments on two machine don't report problems but I install it recently on another computer and receive the exception:</p>

<blockquote>
  <p>Unable to cast COM object of type 'System.__ComObject' to interface type 'NetFwTypeLib.INetFwRule3'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B21563FF-D696-4222-AB46-4E89B73AB34A}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)) </p>
</blockquote>

<p>After read this posts:</p>

<ul>
<li><a href="https://stackoverflow.com/questions/9788135/exception-from-hresult-0x80004002-e-nointerface">Exception from HRESULT: 0x80004002 (E_NOINTERFACE)</a></li>
<li><a href="https://stackoverflow.com/questions/16938467/why-cannot-i-cast-my-com-object-to-the-interface-it-implements-in-c">Why cannot I cast my COM object to the interface it implements in C#</a></li>
<li><a href="https://social.msdn.microsoft.com/Forums/vstudio/en-US/a4ca779c-ae74-48db-9fb8-efaaa6edd3aa/invalidcastexception-exception-from-hresult-0x80004002-enointerface?forum=csharpgeneral" rel="nofollow noreferrer">InvalidCastException , Exception from HRESULT: 0x80004002 (E_NOINTERFACE) </a></li>
</ul>

<p>I set <code>STAThreadAttribute</code> to the Main method of this code to test if with this I resolve the problem, but without any solution:</p>

<pre><code>class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        try{
            var type = Type.GetTypeFromProgID("HNetCfg.FWRule");
            var instance = (INetFwRule3) Activator.CreateInstance(type);

            Console.WriteLine("OK");
        }
        catch (Exception exception){
            Console.WriteLine(exception);
        }
    }
}
</code></pre>

<p>I was surprised went I run this script to find the CLSID on registry, and don't return any result on both computers, where works and does not work.:</p>

<pre><code>reg query HKCR\CLSID | find /i "{B21563FF-D696-4222-AB46-4E89B73AB34A}"
</code></pre>

<p>These are the information from the computer where the service works:</p>

<pre><code>**OS**
Windows Server 2012 R2 Standard

**FirewallAPI.dll file on Windows/system32**
File version: 6.3.9600.17415
Product version: 6.3.9600.17415
Size: 736 kb 
Date modified: 4/28/2015 8:51 PM
</code></pre>

<p>Information from the computer where the service fails:</p>

<pre><code>**OS**
Windows Server 2011 Service Pack 1

**FirewallAPI.dll file on Windows/system32**
File version: 6.1.7600.16385
Product version: 6.3.7600.16385
Size: 730 kb 
Date modified: 7/13/2009 8:51 PM
</code></pre>

<p><strong>QUESTIONS:</strong></p>

<ul>
<li>It can be the difference of version of FirewallAPI.dll what causes the problem?</li>
<li>If so would suffice to update dll, although it seems a bit dangerous by possible inconsistents on the registry?</li>
</ul>