What's the difference setting Embed Interop Types true and false in Visual Studio?

C#Visual Studio

C# Problem Overview


In Visual Studio, when adding one reference to the project, the properties window has an option Embed Inteop Types, should we set it to True or False? What's the difference?

Since we have a lot of projects, among some of them, reference was set to False, others were set to True, it is totally mess up. And the bulid server also have the same warnings:

> What does “reference was created to embedded interop assembly” mean?

So we plan to change all the Embed Inteop Types to False, what risk would we get?

C# Solutions


Solution 1 - C#

This option was introduced in order to remove the need to deploy very large PIAs (Primary Interop Assemblies) for interop.

It simply embeds the managed bridging code used that allows you to talk to unmanaged assemblies, but instead of embedding it all it only creates the stuff you actually use in code.

Read more in Scott Hanselman's blog post about it and other VS improvements here: CLR and DLR and BCL, oh my! - Whirlwind Tour around .NET 4 (and Visual Studio 2010) Beta 1.

As for whether it is advised or not, I'm not sure as I don't need to use this feature. A quick web search yields a few leads:

The only risk of turning them all to false is more deployment concerns with PIA files and a larger deployment if some of those files are large.

Solution 2 - C#

I noticed that when it's set to false, I'm able to see the value of an item using the debugger. When it was set to true, I was getting an error - item.FullName.GetValue The embedded interop type 'FullName' does not contain a definition for 'QBFC11Lib.IItemInventoryRet' since it was not used in the compiled assembly. Consider casting to object or changing the 'Embed Interop Types' property to true.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJerry BianView Question on Stackoverflow
Solution 1 - C#Adam HouldsworthView Answer on Stackoverflow
Solution 2 - C#user890332View Answer on Stackoverflow