VS2010 COM互操作错误解决方法吗? (INetFwMgr)解决方法、错误、操作、COM

2023-09-06 14:21:17 作者:有条河丶叫忘情川

(修改:。解决,解决办法很简单 - 打造2008SP1,以产生Interop.NetFwTypeLib.dll,只是把它作为一个第三方组件感谢里克Sladkey)

我已经升级了一些code(楼下)仍然在净3.5引用COM对象VS 2010年。照片  该版本是自那以后破:(?的类型或命名空间名称INetFwMgr'找不到(是否缺少using指令或程序集引用))...

我发现了一个微软漏洞,如果​​有人说:

  

SDK 4.0 tlbimp.exe是总进口   第一个,它不遵循   正确的流。即使你手动   呼叫tlbimp.exe是并给予正确的   路径。这是根本原因   问题。任何驻留在COM DLL   非默认流将具有相同   问题tlbimp.exe是4.0。

和后跟:

  

3.5的SDK tlbimp.exe是不具有此   问题。一个解决方法是使用3.5   tlbimp.exe是手动导入   从完整路径互操作程序集   它被存储在注册表和   引用这个互操作组件   你的项目。

有人可以解释的解决方法吗? (我尝试了明显的 TLBIMP COM_DLL / OUT = OUT_DLL ,没有好)。

是否有人遇到这种与其它COM?

谢谢!

注:XP ... 然而,另注:试过VS2010 SP1中也没有运气

在code(部分...):

 使用NetFwTypeLib;

命名空间的Utils
{
    公共类MSFIREWALL
    {
               私人常量字符串CLSID_FIREWALL_MANAGER ={304CE942-6E39-40D8-943A-B913C40C9CD4};

        私人NetFwTypeLib.INetFwMgr GetFirewallManager()
        {
                键入的objectType = Type.GetTypeFromCLSID(新的GUID(CLSID_FIREWALL_MANAGER));
                返回Activator.CreateInstance(的objectType)为NetFwTypeLib.INetFwMgr;
        }


    }
}
 
vs2010安装方法是什么 如何下载安装vs2010软件

解决方案

您VS2010的解决方案能够成功地利用了互操作的库,例如:

Interop.NetFwTypeLib.dll

生成或者使用工具VS2008的解决方案,或使用旧的SDK工具手工创建的。

如果您使用的是源代码控制然后就生成与VS2008的互操作库一次,并检查它,然后从VS2010的解决方案中添加引用的互操作库而不是浏览到COM组件进行检查。

(EDIT: solved , solution was simple - build in 2008SP1, take the generated Interop.NetFwTypeLib.dll and simply use it as a 3rd Party assembly. Thanks Rick Sladkey.)

I've upgraded some code (down below) referencing a COM object to VS 2010. Still on .Net 3.5. The build is broken since then: (The type or namespace name 'INetFwMgr' could not be found (are you missing a using directive or an assembly reference?))...

I found a Microsoft bug, where someone stated:

SDK 4.0 tlbimp.exe always imports the first one, it doesn't follow the correct stream. Even if you manually call tlbimp.exe and give the correct path. This is the root cause of the problem. Any COM dll that resides in a non-default stream will have same problem with tlbimp.exe of 4.0.

And followed by:

SDK 3.5 tlbimp.exe doesn't have this problem. A work around is to use 3.5 tlbimp.exe to manually import the Interop assembly from the full path as it is stored in registry and the reference this Interop assembly in your projects.

Can someone explain the workaround ? (i tried the obvious tlbimp COM_DLL /out=OUT_DLL, no good).

Did someone encounter this with another COM ?

Thanks!

Note: XP... Yet another note: Tried the VS2010 SP1 as well, no luck.

The code (partial...):

using NetFwTypeLib;

namespace Utils
{
    public class MSFirewall
    {
               private const string CLSID_FIREWALL_MANAGER = "{304CE942-6E39-40D8-943A-B913C40C9CD4}";

        private NetFwTypeLib.INetFwMgr GetFirewallManager()
        {
                Type objectType = Type.GetTypeFromCLSID(new Guid(CLSID_FIREWALL_MANAGER));
                return Activator.CreateInstance(objectType) as NetFwTypeLib.INetFwMgr;
        }


    }
}

解决方案

Your VS2010 solution can successfully utilize an interop library such as:

Interop.NetFwTypeLib.dll

generated either with a utility VS2008 solution or created by hand using older SDK tools.

If you are using source control then just generate the interop library with VS2008 once and check it in and then add a reference from the VS2010 solution to the checked in interop library instead of navigating to the the COM component.