views:

1833

answers:

3

I am creating an 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.

+11  A: 

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

Btw, I'd thoroughly recommend upgrading from VS2010b2 to the release candidate - it's much, much faster and more stable too, in my experience.

Jon Skeet
Thanks, changing the property was just what I wanted but I couldn't found it.
Jan
+3  A: 

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

JaredPar
+2  A: 

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 (I my case WIA) and then click properties. And there should be the option there for Embed Interop Assembly.

giddy