MEF: Unable to load one or more of the requested types
I recently walked into an issue with a WPF MEF application. The issues was only occurring on my machine, and not a colleagues. On starting the WPF application thought Visual Studio 2010 the exception “Unable to load one or more of the requested types” would be thrown inside DefaultPrismServiceRegistrar.GetRequiredPrismPartsToRegister(AggregateCatalog aggregateCatalog):
private static IEnumerable<ComposablePartDefinition> GetRequiredPrismPartsToRegister(AggregateCatalog aggregateCatalog)
{
List<ComposablePartDefinition> partsToRegister = new List<ComposablePartDefinition>();
var catalogWithDefaults = GetDefaultComposablePartCatalog();
foreach (var part in catalogWithDefaults.Parts)
{
foreach (var export in part.ExportDefinitions)
{
bool exportAlreadyRegistered = false;
foreach (var registeredPart in aggregateCatalog.Parts)
{
foreach (var registeredExport in registeredPart.ExportDefinitions)
{
if (string.Compare(registeredExport.ContractName, export.ContractName, StringComparison.Ordinal) == 0)
{
exportAlreadyRegistered = true;
break;
}
}
}
if (exportAlreadyRegistered != false) continue;
if (!partsToRegister.Contains(part))
{
partsToRegister.Add(part);
}
}
}
return partsToRegister;
}
It transpires that one of the application modules had referenced WPFToolkit.VisualStudio.Design which I assume is only for the Visual Studio design surface. Solution, remove the assembly reference.
Advertisement

I’m sure it wasn’t your intention, but you have just educated me that MEF is something you can use in WPF. I thought it was a Silverlight framework.
This is a handy tool for to find out what imports are not being matched http://msdn.microsoft.com/en-us/library/ff576068.aspx in an application.