简体   繁体   中英

Mixing MEF parts targetting .NET 3.5 with an application targetting .NET 4.0

The Managed Extensibility Framework is both a stand-alone project (currently targetting .NET 3.5) and part of the .NET 4.0 framework.

Suppose I create assemblies targetting .NET 3.5 that contain MEF parts. These assemblies will reference the stand-alone version of System.ComponentModel.Composition.dll .

Now suppose I create a MEF-enabled application targetting .NET 4.0. This application will reference the System.ComponentModel.Composition.dll that comes with the .NET 4.0 framework. Will I be able to use the aforementioned MEF parts in this application?

Unfortunately this will not work because you the 3.5 version of System.ComponentModel.Composition.dll can only be produced by building the codeplex drop and isn't signed by the same key as the official 4.0 version so the CLR will load both assemblies and treat the attributes as two different attributes. So assuming the application is using the .Net 4.0 version of System.ComponentModel.Compsition.dll and constructs the Catalog/Container it will only find parts that were marked with attributes from the .Net 4.0 version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM