에 나는 System.ComponentModel.Composition.dll 버전을 사용하여 .NET 3.5 프레임 워크에서 잘 작동 인터넷에서 쉽게 샘플을 가지고 V2.0.50727은 MEF - 마이그레이션 .NET 3.5에서 .NET 4.0
프로젝트 정의를 변경하고 대상을 .NET 4.0으로 변경했으며 완벽하게 작동합니다.
위의 .dll의 v2.0.50727 버전을 v4.0.30319 인 최신 버전으로 바꾸면 컨테이너 구성 중에 오류가 발생합니다. 다음과 같이 휴식 코드는 다음과 같습니다
private void LoadPlugins() {
var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
var container = new CompositionContainer(catalog);
container.ExportsChanging += new EventHandler(container_ExportsChanging);
var batch = new CompositionBatch();
batch.AddPart(this);
container.Compose(batch); // throws Exception
}
을 그리고 예외는 다음과 같다 :
System.ComponentModel.Composition.ChangeRejectedException was unhandled
Message=The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.
1) More than one export was found that matches the constraint '((exportDefinition.ContractName == "MefTutorial.IPlugin") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "MefTutorial.IPlugin".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))'.
Resulting in: Cannot set import 'MefTutorial.PluginConsumer._myPlugins (ContractName="MefTutorial.IPlugin")' on part 'MefTutorial.PluginConsumer'.
Element: MefTutorial.PluginConsumer._myPlugins (ContractName="MefTutorial.IPlugin") --> MefTutorial.PluginConsumer
내가 MEF에 관한 .NET 4.0로 마이그레이션하려면 어떻게해야합니까?
'IEnumerable'과'ImportMany'를 사용할 수 없습니까? 나를 위해 최소한 작품, 그리고 강하게 입력되는 장점이 있습니다. –
Femaref