尝试使用ServiceLocator.Current.GetInstance()方法获取对象时,我们遇到错误。
尝试获取IXXXXXController类型的实例时出现激活错误,键“”
at Microsoft.Internal.Collections.WeakReferenceCollection 1.<CleanupDeadReferences>b__0(WeakReference w)
at System.Collections.Generic.List
1.RemoveAll(Predicate 1 match)
at Microsoft.Internal.Collections.WeakReferenceCollection
1.CleanupDeadReferences()
在Microsoft.Internal.Collections.WeakReferenceCollection`1.Add(T item)
在System.ComponentModel.Composition.Hosting.ImportEngine.StartSatisfyingImports(PartManager partManager,AtomicComposition atomicComposition)
在System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager,ComposablePart part,Boolean shouldTrackImports)
在System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImports(ComposablePart部分)
在System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine,ComposablePart part,
ExportDefinition定义)
在System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(CatalogPart part,ExportDefinition export,Boolean isSharedPart)
在System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedValueCore()
在System.ComponentModel.Composition.Primitives.Export.get_Value()
在System.ComponentModel.Composition.ReflectionModel.ImportingItem.Cast(类型类型,导出导出)
在System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastSingleExportToImportType(类型类型,导出导出)
在System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastExportsToSingleImportType(Export [] exports)
在System.ComponentModel.Composition.ReflectionModel.ImportingItem.CastExportsToImportType(Export [] exports)
在System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportingItem item,Export [] exports)
在System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.SetImport(ImportDefinition定义,IEnumerable 1 exports)
at System.ComponentModel.Composition.Hosting.ImportEngine.PartManager.TrySetImport(ImportDefinition import, Export[] exports)
at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable
1进口,AtomicComposition
atomicComposition) 在System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportsStateMachine(PartManager partManager,ComposablePart部分) 在System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImports(PartManager partManager,ComposablePart part,Boolean shouldTrackImports) 在System.ComponentModel.Composition.Hosting.ImportEngine.SatisfyImports(ComposablePart部分) 在System.ComponentModel.Composition.Hosting.CompositionServices.GetExportedValueFromComposedPart(ImportEngine engine,ComposablePart part,
ExportDefinition定义)
在System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportedValue(CatalogPart part,ExportDefinition export,Boolean isSharedPart)
在System.ComponentModel.Composition.Hosting.CatalogExportProvider.CatalogExport.GetExportedValueCore()
在System.ComponentModel.Composition.Primitives.Export.get_Value()
在System.ComponentModel.Composition.ExportServices.GetCastedExportedValue [T](导出导出)
在System.ComponentModel.Composition.ExportServices。&lt;&gt; c__DisplayClass10 2.<CreateSemiStronglyTypedLazy>b__c()
at System.Lazy
1.CreateValue()
在System.Lazy 1.LazyInitValue()
at System.Lazy
1.get_Value()
at c:\ release \ WorkingDir
\ PrismLibraryBuild \ PrismLibrary \ Desktop \ Prism.MefExtensions \ MefServiceLocatorAdapter.cs:第73行 在Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(类型serviceType,String key)
我们在类中设置容器(在覆盖void ConfigureAggregateCatalog 方法中)从MefBootstrapper派生,如下所示
this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ClassName).Assembly));
我们观察到这项工作有一段时间了,但是当我们离开应用程序理想的几个小时后,我们就开始收到错误。请建议导致此错误的原因并进行修复。
由于
答案 0 :(得分:-1)
不要在棱镜上使用MEF。 MEF支持将在未来的版本中被删除。请使用真正的容器。