BT

Your opinion matters! Please fill in the InfoQ Survey!

.NET 4 Feature Focus: Type Embedding and Equivalence

| by Jonathan Allen Follow 257 Followers on Oct 27, 2008. Estimated reading time: 1 minute |

A note to our readers: As per your request we have developed a set of features that allow you to reduce the noise, while not losing sight of anything that is important. Get email and web notifications by choosing the topics you are interested in.

Probably the most common problems with COM Interopt in .NET applications is deployment and versioning. Currently developers have to include "Primary Interopt Assemblies", which in the case of applications like Office be a megabyte or larger. With .NET 4 that will no longer be an issue.

COM Type Embedding allows fragments of interfaces to be compiled into the assemblies that need them. Only the interfaces and methods actually used by the program are included, drastically reducing the overall size of the application.

To keep the VTables accurate, gap commands are included in the assembly's IL as placeholders. These indicate how many method slots are to be skipped. Since COM doesn't allow methods to change location in published interfaces, this will allow support for both forward and backwards versioning.

Another issue this addresses is compiling an application against a newer version, say Word 2007, when the end user may have Word 2003. Checking to see if a method actually exists in the runtime version will have be done in user code, otherwise an access violation will occur. But so long as only backwards compatible methods are used, there should be no other issues.

The use of this will be controlled via a compiler flag. It will default to off for old projects and on for new ones. In the rare event that COM Type Embedding won't work for a given COM interface, a compiler error will occur recommending the flag be turned off.

Two related features are Type Equivalence and Managed Type Embedding. These allows types in different assemblies to be treated as being the same type at runtime. This is crucial for scenarios where multiple libraries are pulling in the same COM interfaces. There are strict rules on this. First of all, all types have to be tagged with a shared GUID so they can be matched up. This isn't an issue with COM, since they are tagged anyways, but it will have to be explicitly applied to managed types.

Regular classes cannot be shared via Type Embedding and Equivalence due to the possibility of differing implementations. Types that can be shared include interfaces, enumerations, delegates, and simple structures.

These features are planned for VB and C#. Developers using C++/CLI normally access COM objects via their header files and Microsoft does not currently plan to offer it for them.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT