【发布时间】:2012-06-19 14:05:38
【问题描述】:
首先,我需要使用第三方 ActiveX 控件。
接下来我必须使用 stdole 库来为第三方控件提供一些图像。 当我在默认设置下编译时,我收到了一些警告:
warning CS1762: A reference was created to embedded interop assembly 'c:\Windows\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll' because of an indirect reference to that assembly created by assembly 'XXX\obj\x86\Release\Interop.ThirdPartyControl.dll'. Consider changing the 'Embed Interop Types' property on either assembly.
warning CS1762: A reference was created to embedded interop assembly 'c:\Windows\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll' because of an indirect reference to that assembly created by assembly 'XXX\obj\x86\Release\AxInterop.ThirdPartyControl.dll'. Consider changing the 'Embed Interop Types' property on either assembly.
很简单,我将遵循该建议并将 Embed Interop Types 设置为 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 上的嵌入互操作会导致库完全无法找到)。
好吧,让我们换个方式,用 Embed Interop 将所有内容标记为 true。 哎呀!编译错误:
Error 2 Cannot embed interop types from assembly 'XXX\obj\x86\Release\AxInterop.ThirdPartyControl.dll' because it is missing either the 'ImportedFromTypeLibAttribute' attribute or the 'PrimaryInteropAssemblyAttribute' attribute XXX\obj\x86\Release\AxInterop.ThirdPartyControl.dll XXX
Error 1 Cannot embed interop types from assembly 'XXX\obj\x86\Release\AxInterop.ThirdPartyControl.dll' because it is missing the 'GuidAttribute' attribute XXX\obj\x86\Release\AxInterop.ThirdPartyControl.dll XXX
那么,关于如何摆脱警告并拥有可以构建和运行的东西的任何建议?
更新
Hans Passant 作为评论发布了一个确实解决问题的答案。如果他将其转发为答案,我会接受。不幸的是,我也遇到了标准问题,即设置为 Copy Local 的 DLL 被很好地复制到其项目的发布文件夹中,但不会移动到解决方案的最终发布文件夹(单独的可执行文件)。我现在通过在我的可执行文件中添加对 stdole 的引用解决了这个问题。我想这可能已经足够了。
【问题讨论】:
-
您不能为 ActiveX 组件嵌入类型。目标机器缺少 stdole 的 PIA,尝试将 Copy Local 属性设置为 true 并复制生成的 stdole.dll。
-
又是汉斯帕桑特!你无处不在,今天早些时候我什至在一件无关的事情上遇到了你。不知道为什么 Jon Skeet 会受到所有媒体的关注。我会尝试并报告。
-
@HansPassant 查看问题更新
标签: c# visual-studio-2010 activex stdole