Can't Silence Embed Interop Warnings

时光毁灭记忆、已成空白 提交于 2020-01-03 09:24:08

问题


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.


回答1:


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.




回答2:


If you create a new project in VS10, it may use .NET framework 4 client profile as default, you can set target framework to .NET Framework 4 in project properties-->Application tab page.



来源:https://stackoverflow.com/questions/11102718/cant-silence-embed-interop-warnings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!