Skip to content

Interop type XXX cannot be embedded. Use the applicable interface instead

24 March 2011

Visual Studio 2010 compiler error: Interop type XXX cannot be embedded. Use the applicable interface instead

Recently, updating an old fine working project to NET 4.0 I was surprised with the error above. Project is using an Interop Assembly and the error was unexpected because it compiles fine under NET 3.5

Converted source to 4.0 I’ve got a line
public MyObjectClass mo;
where I’ve got the error
Interop type XXX cannot be embedded. Use the applicable interface instead

Poking around I found two comprehensive posts with different working solutions: one is setting Embed Interop Types to false;
Interop Type

the other is from Misha Shneerson

Unfortunately neither of them were suitable for me so I decided to try reflecto NET. There, the solutions come easy.

I found MyObjectClass and just above was required interface.

public interface MyObject ...
public class MyObjectClass : MyObject

so I replaced
public MyObjectClass mo;
with
public MyObject mo;
and error disappeared.

That’s it. Hope this will be useful…

Advertisements

From → NET

3 Comments
  1. Mark permalink

    Very useful, thank you

  2. I wouldn’t be commenting if I didn’t like this blog.. you’re a great writer & I’m quite impressed to say the least. keep up the nice work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: