简体   繁体   English

将针对.NET 3.5的MEF部件与针对.NET 4.0的应用程序混合使用

[英]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. Managed Extensibility Framework既是一个独立项目(目前面向.NET 3.5),也是.NET 4.0框架的一部分。

Suppose I create assemblies targetting .NET 3.5 that contain MEF parts. 假设我创建了包含MEF部件的.NET 3.5程序集。 These assemblies will reference the stand-alone version of System.ComponentModel.Composition.dll . 这些程序集将引用System.ComponentModel.Composition.dll的独立版本。

Now suppose I create a MEF-enabled application targetting .NET 4.0. 现在假设我创建了一个支持MEF的应用程序,目标是.NET 4.0。 This application will reference the System.ComponentModel.Composition.dll that comes with the .NET 4.0 framework. 此应用程序将引用.NET 4.0框架附带的System.ComponentModel.Composition.dll Will I be able to use the aforementioned MEF parts in this application? 我是否可以在此应用中使用上述MEF部件?

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. 不幸的是,这不起作用,因为您只能通过构建codeplex drop生成3.5版本的System.ComponentModel.Composition.dll,并且没有使用与官方4.0版本相同的密钥签名,因此CLR将加载两个程序集并处理属性为两个不同的属性。 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. 因此,假设应用程序使用.Net 4.0版本的System.ComponentModel.Compsition.dll并构造Catalog / Container,它将只查找标有.Net 4.0版本属性的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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