we are currently using MEF (Managed Extensibility Framework, http://mef.codeplex.com/ ) and it throws out exceptions, with limited information to proceed on.
is there a way to debug MEF exceptions?
My exception is like this:
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports(ImportDefinition definition)
at System.ComponentModel.Composition.Hosting.AggregateCatalog.GetExports(ImportDefinition definition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExports(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ImportEngine.TryGetExports(ExportProvider provider, ComposablePart part, ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ImportEngine.TrySatisfyImportSubset(PartManager partManager, IEnumerable`1 imports, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ImportEngine.TryPreviewImportsStateMachine(PartManager partManager, ComposablePart part, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ImportEngine.PreviewImports(ComposablePart part, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ComposablePartExportProvider.Compose(CompositionBatch batch)
at System.ComponentModel.Composition.Hosting.CompositionContainer.Compose(CompositionBatch batch)
at System.ComponentModel.Composition.AttributedModelServices.ComposeParts(CompositionContainer container, Object[] attributedParts)
at MyApp.Extension..ctor(Assembly assembly) in W:\MyApp\Source\Extensions\Extension.cs:line 45
OK
The Code is simple:
var aggregateCatalog = new AggregateCatalog();
_assembly = assembly;
var assemblyCatalog = new AssemblyCatalog(assembly);
aggregateCatalog.Catalogs.Add(new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()));
aggregateCatalog.Catalogs.Add(assemblyCatalog);
_compositionContainer = new CompositionContainer(aggregateCatalog);
_compositionContainer.ComposeParts(this);
I feel your pain. When I'm stuck, I typically dump the MEF composition information to get more information on the cause of the composition failure. For instructions on how to do this, see Diagnosing Composition Problems in the MEF Programming Guide or the Debugging MEF topic on MSDN.
In .NET 4.5 (or the current MEF 2 preview 4 release available on codeplex) there is a simpler option: you can improve the usefulness of the error message by disabling silent rejection in the CompositionOptions which you pass to the container constructor.
edit: ah, you're getting a
ReflectionTypeLoadException
. That's another matter: it means that the types in some assembly cannot be successfully loaded, typically because they reference other types that cannot be found. In your code example, you should be able to reproduce the problem by invokingassembly.GetTypes()
, without involving MEF.Daniel Plaisted has written quite an in-depth blog article about diagnosing issues with MEF.
Can you show us what exceptions are being thrown?