无法静音嵌入互操作警告



首先,我有一个第三方ActiveX控件需要使用。

接下来,我必须使用 stdole 库来为第三方控件提供一些图像。当我在默认设置下编译时,我收到一些警告:

warning CS1762: A reference was created to embedded interop assembly 'c:WindowsassemblyGACstdole7.0.3300.0__b03f5f7f11d50a3astdole.dll' because of an indirect reference to that assembly created by assembly 'XXXobjx86ReleaseInterop.ThirdPartyControl.dll'. Consider changing the 'Embed Interop Types' property on either assembly.
warning CS1762: A reference was created to embedded interop assembly 'c:WindowsassemblyGACstdole7.0.3300.0__b03f5f7f11d50a3astdole.dll' because of an indirect reference to that assembly created by assembly 'XXXobjx86ReleaseAxInterop.ThirdPartyControl.dll'. Consider changing the 'Embed Interop Types' property on either assembly.

很简单,我将遵循该建议,并将嵌入互操作类型设置为 false 作为 stdole 引用。 一切看起来都很好,直到我现在转到客户端计算机,突然应用程序抛出以下内容:

Could not load file or assembly 'stdole, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

所以,我想这不会发生(尽管我不确定为什么删除 stdole 上的嵌入互操作会使库完全无法找到)。

好吧,让我们走另一条路,用嵌入互操作 true 标记所有内容。哎呀! 编译错误:

Error   2   Cannot embed interop types from assembly 'XXXobjx86ReleaseAxInterop.ThirdPartyControl.dll' because it is missing either the 'ImportedFromTypeLibAttribute' attribute or the 'PrimaryInteropAssemblyAttribute' attribute XXXobjx86ReleaseAxInterop.ThirdPartyControl.dll XXX
Error   1   Cannot embed interop types from assembly 'XXXobjx86ReleaseAxInterop.ThirdPartyControl.dll' because it is missing the 'GuidAttribute' attribute  XXXobjx86ReleaseAxInterop.ThirdPartyControl.dll XXX

那么,关于如何摆脱警告并拥有可以构建和运行的东西的任何建议?

更新

汉斯·帕桑特(Hans Passant)发表了一个确实可以解决问题的答案作为评论。 如果他转发它作为答案,我会接受它。 不幸的是,我也遇到了一个标准问题,即设置为"复制本地"的 DLL 被很好地复制到其项目的发布文件夹中,但随后不会移动到解决方案的最终发布文件夹(单独的可执行文件)。 现在,我已经通过在可执行文件中添加对 stdole 的引用来解决这个问题。 我想这可能已经足够好了。

Hans Passant的回答:

不能嵌入 ActiveX 组件的类型。目标计算机缺少 stdole 的 PIA,请尝试将"复制本地"属性设置为 true.dll并复制生成的 stdole。

如果在VS10中创建新项目,则默认使用.NET Framework 4客户端配置文件,可以在项目属性-->应用程序选项卡页中将目标框架设置为.NET Framework 4。

最新更新