无法静音嵌入互操作警告 [英] Can't Silence Embed Interop Warnings

查看:151
本文介绍了无法静音嵌入互操作警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

  warning CS1762:已创建对嵌入式的引用互操作程序集 c:\Windows\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll,因为间接引用了由程序集 XXX\obj\x86\创建的程序集释放 Interop.ThirdPartyControl.dll。考虑更改两个程序集上的嵌入式互操作类型属性。 
警告CS1762:由于间接引用了该程序集,所以创建了对嵌入式互操作程序程序集'c:\Windows\assembly\GAC\stdole\7.0.3300.0__b03f5f7f11d50a3a\stdole.dll'的引用由程序集 XXX\obj\x86\Release\AxInterop.ThirdPartyControl.dll创建。考虑更改两个程序集上的嵌入式互操作类型属性。

很容易,我会遵循该建议,并将Embed Interop Types设置为false以供参考。一切看起来都很好,直到我现在转到客户端计算机为止,突然,应用程序抛出了这个错误:

 无法加载文件或程序集 stdole,版本= 7.0.3300.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a或其依赖项之一。该系统找不到指定的文件。 

因此,我想这不会发生(尽管我不确定为什么要删除stdole上的嵌入互操作

好吧,让我们走另一条路,将Embed Interop标记为true。
哎呀!编译错误:

 错误2无法嵌入程序集'XXX\obj\x86\Release\AxInterop中的互操作类型。 ThirdPartyControl.dll,因为它缺少 ImportedFromTypeLibAttribute属性或 PrimaryInteropAssemblyAttribute属性XXX\obj\x86\Release\AxInterop.ThirdPartyControl.dll XXX 
错误1无法从程序集嵌入互操作类型'XXX\obj\x86\Release\AxInterop.ThirdPartyControl.dll',因为它缺少'GuidAttribute'属性XXX\obj\x86\Release\AxInterop.ThirdPartyControl.dll XXX

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



更新



Hans Passant作为评论发布了确实能够解决问题的答案。如果他将其重新发布为答案,我会接受。不幸的是,我还有一个标准问题,就是将设置为本地复制的DLL很好地复制到其项目的发布文件夹中,但是随后不会转到该解决方案的最终发布文件夹(一个单独的可执行文件)。我现在通过在可执行文件中添加对stdole的引用来解决此问题。我想这可能已经足够了。

解决方案

汉斯·帕桑特的答案:



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


First I've got a third party ActiveX control I need to use.

Next I've got to use the stdole library to feed that third party control some images. When I compile under the default settings, I get some warnings:

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.

Easy enough, I'll follow that advice and set Embed Interop Types to false for the stdole reference. Everything looks good until I go to the client machine now, when suddenly the application is throwing up this:

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.

So, I guess that's not gonna happen (though I'm not sure WHY removing embed interop on stdole has the effect of making the library unfindable altogether).

Well, let's go the other way and mark everything with Embed Interop true. OOPS! Compile error:

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

So, any advice on how to get rid of the warnings and have something that can be built and run?

UPDATE

Hans Passant posted as a comment an answer that does indeed solve the problem. If he reposts it as an answer I'll accept it. Unfortunately I'm also having the standard problem where the DLL that's set to Copy Local is nicely copied into its project's release folder, but won't then move along to the final release folder for the solution (a separate executable). I've solved that for now by adding a reference to stdole in my executable. I suppose that's probably good enough.

解决方案

Answer by Hans Passant:

You cannot embed types for an ActiveX component. The target machine is missing the PIA for stdole, try setting the Copy Local property to true and copy the generated stdole.dll as well.

这篇关于无法静音嵌入互操作警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆