I wrote a Windows Service that use Firewall COM library Interop.NetFwTypeLib
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:
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))
After read this posts:
- Exception from HRESULT: 0x80004002 (E_NOINTERFACE)
- Why cannot I cast my COM object to the interface it implements in C#
- InvalidCastException , Exception from HRESULT: 0x80004002 (E_NOINTERFACE)
I set STAThreadAttribute
to the Main method of this code to test if with this I resolve the problem, but without any solution:
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);
}
}
}
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.:
reg query HKCR\CLSID | find /i "{B21563FF-D696-4222-AB46-4E89B73AB34A}"
These are the information from the computer where the service works:
**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
Information from the computer where the service fails:
**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
QUESTIONS:
- It can be the difference of version of FirewallAPI.dll what causes the problem?
- If so would suffice to update dll, although it seems a bit dangerous by possible inconsistents on the registry?