使从 WCF 导入的枚举在 COM Interop 中可见

发布于 2024-10-08 05:30:41 字数 698 浏览 2 评论 0原文

我有几个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人│生佛魔见 2024-10-15 05:30:41

创建一个在客户端和服务之间共享的公共库。在该程序集中添加枚举器并用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文