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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With