Interop type cannot be embedded

398,112

Solution 1

.NET 4.0 allows primary interop assemblies (or rather, the bits of it that you need) to be embedded into your assembly so that you don't need to deploy them alongside your application.

For whatever reason, this assembly can't be embedded - but it sounds like that's not a problem for you. Just open the Properties tab for the assembly in Visual Studio 2010 and set "Embed Interop Types" to "False".

EDIT: See also Michael Gustus's answer, removing the Class suffix from the types you're using.

Solution 2

In most cases, this error is the result of code which tries to instantiate a COM object. For example, here is a piece of code starting up Excel:

Excel.ApplicationClass xlapp = new Excel.ApplicationClass();

Typically, in .NET 4 you just need to remove the 'Class' suffix and compile the code:

Excel.Application xlapp = new Excel.Application();

An MSDN explanation is here.

Solution 3

Like Jan It took me a while to get it .. =S So for anyone else who's blinded with frustration.

  • Right click the offending assembly that you added in the solution explorer under your project References. (In my case WIA)
  • Click properties.
  • And there should be the option there for Embed Interop Assembly.
  • Set it to False

Solution 4

Here's where to set the Embed Interop in Visual Studio 2012

enter image description here

Solution 5

Expanding on Jon's correct answer.

The problem here is that your are combining the new "Embed Interop Types" (or NoPIA) feature with use of a class type. The "Embed Interop Types" feature works by essentially statically linking in all of the types from a PIA (Primary Interop Assembly) into the referencing assembly removing the overhead of deploying it.

This feature works great for most types in a PIA but it does have restrictions. One of them is that you cannot embed classes (it's a servicing issue). Misha has a detailed blog article on why this is not allowed

Share:
398,112
Jan
Author by

Jan

Updated on February 22, 2020

Comments

  • Jan
    Jan about 4 years

    I am creating a web application on the .NET 4.0 framework (beta2) in C#.

    When I try to use a assembly called "ActiveHomeScriptLib", I get the following error:

    Interop type 'ActiveHomeScriptLib.ActiveHomeClass' cannot be embedded. Use the applicable interface instead.

    When I change the framework to version 3.5, I don't have any errors.

    What is an Interop Type and why does this only occur when I use the 4.0 framework?

  • Dave
    Dave almost 13 years
    Unfortunately, this sounds like just what I need, but this property doesn't seem to be available anymore.
  • SteveWilkinson
    SteveWilkinson almost 13 years
    Still struggling till I realised you had to right-click the interop assembly under the project References in Solution Explorer, NOT the assembly you're building!
  • Rana Hamza
    Rana Hamza over 12 years
    I was looking in the Project's property page instead of the right-click | Properties on the effected DLL in the References pane.
  • Tim Goodman
    Tim Goodman about 12 years
    Wouldn't it make more sense to do as the error says and "use the applicable interface"? I had this error (from a different class) and was able to instantiate an interface which had that class specified as its CoClass attribute, and it worked. As in Michael Gustus' answer below, the interface for BlahClass was just called Blah, which seems to be the standard convention.
  • Tim Goodman
    Tim Goodman about 12 years
    +1 I believe this is what the error message is actually telling you to do when it says "use the applicable interface". Note that Excel.Application is an interface (despite the fact that it can be instantiated with the new keyword, similar to the situation described here: stackoverflow.com/questions/6960910/… )
  • Schmuli
    Schmuli about 12 years
    A great thing about embedding is that the Interop assembly can remain CopyLocal=False, as you don't need it at runtime.
  • Kiquenet
    Kiquenet about 9 years
    "Embed Interop Types" to "False" or "True" ?
  • Sam Holder
    Sam Holder over 8 years
    @Kiquenet if you follow the advice here you can set the 'Embed Interop Types' back to True, or at least that worked ok for me
  • majestzim
    majestzim over 8 years
    This approach worked for me as well! In my case, I was debugging to find where the value I needed was, right-clicked and selected "copy expression". What was given to me was "...HTMLDocumentClass..." Removing the text "Class" from it solved the issue for me.
  • user3564895
    user3564895 almost 8 years
    This also worked for VS2015 c# with .net using PP_COM_Wrapper; given in cypress.com Cypress Semiconductor Corporation C# Lib example. Setting to False got rid of the error.
  • Prokurors
    Prokurors over 7 years
    @TimGoodman for me "applicable interface" was not working, but setting above mentioned embed interop types property to false did the trick. In my case - I was working with Microsoft.Office.Interop.Excel library and needed to access Workbook object. Using it's interface Workbook (btw. naming convention...) was not an option - I received COM object, not the desired Microsoft.Office.Interop.Excel.WorkbookClass
  • NeXuS
    NeXuS almost 7 years
    @Prokurors You often need an explicit cast from "object" to the desired type
  • David Foley
    David Foley about 5 years
    Now, (ten years later) this option is called "Embed Interop Types"