2017-07-06 35 views
0

当我尝试使用ComSourceInterfaces而不是typeof字符串参数时,我无法将程序集注册为COM对象。我正在实现多个接口,因为这是SDK所要求的。当我尝试使用ComSourceInterfaces而不是typeof字符串参数时,我无法将程序集注册为COM对象

当我使用

[ComVisible(true), 
ClassInterface(ClassInterfaceType.None), 
ComSourceInterfaces("IAccessControl"), 
Guid("738CFFEF-37DC-4C61-957E-C5A78FE20223")] 
public class EventGeneratorV2 : IAccessControl 

我得到的错误

错误MSB3217:无法注册程序集 “... \事件产生v2.dll”。无法从程序集'加载类型'IAccessControl'事件 Generator v2,Version = 1.1.0.0,Culture = neutral, PublicKeyToken = bffdb712704a75b7'。

但是,如果我改变我的代码使用

[ComVisible(true), 
ClassInterface(ClassInterfaceType.None), 
ComSourceInterfaces(typeof(IAccessControl)), 
Guid("738CFFEF-37DC-4C61-957E-C5A78FE20223")] 
public class EventGeneratorV2 : IAccessControl 

它正确地做工作。我也尝试了IAccessControl接口的完全限定名,Lib.Interfaces.IAcccessControl作为字符串,但仍然失败。最好的解决方案是使用多个ComSourceInterfaces,但只能使用一次,最多使用4个接口。为了与其他软件兼容,我需要实现9个接口。有没有办法让字符串工作?

回答

0

好吧我想通了。字符串实际上是每个接口的“Lib.Interfaces.IAcccessControl,Lib”。其中第一部分是接口的完全限定名称,lib是接口来自的参考。

然后当我添加其他接口时,我必须在每个接口之间添加\ 0。所以我的最后ComSourceInterfaces是相当长的

ComSourceInterfaces("Lib.Interfaces.IAccessControl, Lib\0Lib.Interfaces.IAccessControl2, Lib\0Lib.Interfaces.ITranslate, Lib\0Lib.Interfaces.ITranslate2, Lib\0Lib.Interfaces.IComConfig, Lib\0Lib.Interfaces.IComConfig2, Lib\0Lib.Interfaces.IInput, Lib\0Lib.Interfaces.IInput2, Lib\0Lib.Interfaces.IAsset, Lib\0Lib.Interfaces.IAsset2, Lib\0Lib.Interfaces.IFakeName, Lib\0Lib.Interfaces.IComManager, Lib\0Lib.Interfaces.IDistributeEvent, Lib") 

之后,DLL编译并正确注册。

相关问题