If you are Office Developers i.e. developing COM Addins, this topic may interest you much.
Problem:
If you are developing COM Addins using .NET 3.5 or earlier, you have to distribute proper PIA (Primary Interop Assembly) along with your installer. Here, PIA are the separate managed (.net) assembly which bridge communication between your application .NET assembly to COM servers. There are separate installer from different Office versions i.e. Office 2000, 2003, 2007 and 2010. The PIA are NOT included in the default installation of the Office Package. And, here ‘proper’ means you must choose just ONE PIA targeted to your client’s office version.
This imposes 3 issues:
- You have to maintain several source control for different PIAs.
- You have to distribute the PIA which is large in size (though you may have only used a small portion of it) and might conflict with existing PIA available on the user.
- Your application may stop working if other remove the PIA from client’s machine.
Solution:
.NET 4 provides an options for Interop assembly to be embedded inside the same Addin assembly. This is called ‘Embed Interop Types’ (boolean). When you set this value to ‘true’, the compiler does some ‘smart’ stuffs for us.
It analyses the uses of interop assembly and creates a new namespace, on the fly, inside the Addin assembly which contains all the classes, struct, interfaces etc used by the program – nothing less, nothing more. Morever, it can treat two structurally identical COM interop types that share the same identifying characteristics (name, GUID and so on) as though they were actually the same .NET type.
These features are called ‘Type Embedding and Equivalence’. It’s not language features of C# but more of Compiler trick.
The Office Addin Built using Addin-Express solutions also rely on the same features. They call it NoPIA. See http://www.add-in-express.com/creating-addins-blog/2010/05/28/net-framework4-nopia-addinexpress2010/ for more info.
Conclusion:
Thus, we MUST always set the ‘Embed Interop Types’ true for the Interop Types when using .NET 4. It’s great advantage. There’re some other kind of development like VS extensibility in which we NEVER set this to ‘true’ because VS already has the Interop assembly needed so embedding again will only increase you deployment project size. See http://www.ittreats.com/microsoft/aspnet/check-your-embed-interop-types-flag-when-doing-visual-studio-extensibility-work.html for more info.
Since this feature is just introduced, it’s side-effects is yet to be known. Anyway, Please let me know your feedback in comments.
Happy Programming!



