使从 WCF 导入的枚举在 COM Interop 中可见
我有几个 WCF 服务已导入到 .Net4 类库中。创建代理时,会将多个声明为 DataContract 的枚举器导入到代理中。后来我通过 COM Interop 公开了几个过程以用作 ActiveX 库,并使用导入的枚举器作为这些过程的参数。
在我的类库的程序中,我可以用[ComVisible(true)]
公开,以便可以通过COM调用它们。但是,当我使用 regasm.exe 注册以枚举器作为参数的方法时,我收到错误:
Type library exporter warning processing 'xxxxxx.Method(pEnumerator),yyyyyy'. Warning: Non COM visible value type 'yyyyyy.zzzzzzz.enEnumerator' is being referenced either from the type currently being exported or from one of its base types.
我知道发生这种情况是因为枚举器未通过 ComVisible 公开,但如果我输入必要的参数,因为它们位于代理,每当我刷新代理时,它们都会被覆盖。有没有这方面的事情?
我可以在类库中创建自己的枚举器,使用 ComVisible 公开它们,并执行switch
以将导入的枚举器与我创建的枚举器相匹配。但我想避免这种情况。
感谢您的帮助
I have several WCF services that I have imported into a .Net4 Class Library. When the proxy is created, several enumerators that are declared as DataContracts are imported into the proxy. I later expose several procedures through COM Interop to be used as ActiveX libraries, and I use the imported enumerators as parameters on these procedures.
In the procedures of my Class Library, I can expose with [ComVisible(true)]
, so that they can be called through COM. However, the methods that have enumerators as parameters, when I register with regasm.exe, I get the error:
Type library exporter warning processing 'xxxxxx.Method(pEnumerator),yyyyyy'. Warning: Non COM visible value type 'yyyyyy.zzzzzzz.enEnumerator' is being referenced either from the type currently being exported or from one of its base types.
I know this happens because the enumerators aren't exposed with ComVisible, but if I put the necessary parameter, since they are in the proxy, anytime I refreshed the proxy, they will be overwritten. Is there anyway around this?
I can create my own enumerators inside the Class Library, expose them with ComVisible, and do a switch
to match the imported enumerators to my created enumerators. But I would like to avoid this.
Tks for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个在客户端和服务之间共享的公共库。在该程序集中添加枚举器并用
ComVisible
标记它们。从 VS 创建代理时,有一个复选框(默认选中)允许重用当前或引用的程序集中的类型。选中此选项后,代理将使用共享程序集中的类型,而不是生成新类型。
Create a common library that is shared between client and service. Add your enumerators in that assembly and mark them with
ComVisible
.While creating proxy from VS, there is a checkbox (checked by default) which allows reusing types in current or referenced assemblies. With this checked, proxy will use types from shared assembly instead of generating new ones.