6

首先,我需要使用第三方 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 的引用解决了这个问题。我想这可能已经足够好了。

4

2 回答 2

3

汉斯·帕桑特的回答:

您不能为 ActiveX 组件嵌入类型。目标机器缺少 stdole 的 PIA,尝试将 Copy Local 属性设置为 true 并复制生成的 stdole.dll。

于 2013-03-29T04:29:48.663 回答
-2

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

于 2013-10-08T08:18:58.647 回答