PDC 2008: Under the Hood Advances in the .NET Type System

(Presenter: Misha Shneerson)

What they said:

Enhancements to the type system in the next version of .NET Framework allow for loose type-coupling of components comprising your application. This talk is an in-depth examination of the changes in the Common Language Runtime and managed languages. See how these changes help to simplify versioning and deployment of components targeting either COM based and/or fully managed applications. For Office developers, learn how to eliminate the need to redistribute primary interop assemblies.

What I said:

Improvements in the compiler and CLR 4.0 allow for generating and embedding local types into your applications where more heavyweight mechanisms are required today. Primary interop assemblies are a well-known way of integrating with native libraries but include numerous methods and features that you may not be taking advantage of in your applications. These additional features expand the size of your application just in case you might want to call them in the future. With the CLR 4.0 the compiler can generate and embed a local interop type that is customized to exactly the features you are using, eliminating the need to load the PIA with a minimal increase in application size. This talk details the implementation of the local type and type embedding features in CLR 4.0. Taking advantage of type embedding can be done simply in Visual Studio by enabling a new embedded property in the property grid for the assembly reference in the project definition, or equivalently from the command line.

The local type feature can be used for more than just interacting with PIAs. When you define an interface that changes and evolves over time as it goes through different versions, the same CLR features can simplify the versioning experience of this add-in model. The use of local types decouples your application from a particular version of the interface, allowing different versions to be loaded as necessary. Any version of the interface can be cast to your local version of the interface. At runtime, the member uses on the objects are tested against the actual implementation of the interface.

Type embedding and the generation of local types for native-code integration and loosely-coupled type versioning will introduce a number of benefits for developers targeting the CLR 4.0. Among the benefits are:

  • simplifed deployment compared to using PIA
  • simplified multi-targeting of applications
  • reduced working set of applications
  • developing versioned interfaces becomes easier because of loose type coupling