Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interop type cannot be embedded

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?

like image 979
Jan Avatar asked Mar 20 '10 15:03

Jan


People also ask

What is embed interop types?

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 set the Embed Interop Type property?

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.


2 Answers

.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.

like image 114
Jon Skeet Avatar answered Sep 19 '22 04:09

Jon Skeet


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.

like image 33
Michael Gustus Avatar answered Sep 21 '22 04:09

Michael Gustus