Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Silence Embed Interop Warnings

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.

like image 291
user12861 Avatar asked Jun 19 '12 14:06

user12861


People also ask

What is Embedinteroptypes?

Embed Interop Types is a new feature of the . NET 4.0 Framework that allows you to include the attribute information that is normally stored in the Primary Interop Assembly (PIA) in the executable or dynamic-link library (DLL) instead.

How do I change the Embed Interop Type property?

To resolve this error, change the value of the Embed Interop Types property to False by following these steps: Select the TestStand Interop Assembly reference in the references section of your project in the Solution Explorer. Find the Embed Interop Types property in the Property Browser, and change the value to False.


1 Answers

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.

like image 87
user12861 Avatar answered Oct 23 '22 18:10

user12861