Is it bug in MefXapModuleTypeLoader?

Topics: Prism v4 - Silverlight 4
Jun 21, 2010 at 3:10 PM


// Because the XAPs loaded will contain assemblies that have references to this assembly, 
// and because this assembly exports singletons, I must filter to only modules to prevent DuplicateAssemblyExceptions.
FilteredCatalog filteredCatalog = new FilteredCatalog(deploymentCatalog,
	   x => x.ExportDefinitions.Where(def => def.ContractName == AttributedModelServices.GetContractName(typeof(IModule))).SingleOrDefault() != null);


Filtering prevents all none IModule exports. So i must inintialize all my exports manually. Something like this:

public class TaskModule : IModule
	public CompositionContainer Container { get; set; }

	public void Initialize()
		var cb = new CompositionBatch();
		cb.AddPart(AttributedModelServices.CreatePartDefinition(typeof(RegionControl), null).CreatePart());
		cb.AddPart(AttributedModelServices.CreatePartDefinition(typeof(TasksMenuItem), null).CreatePart());

Is it bug or by design?

Jul 22, 2010 at 11:42 PM


Thanks for reporting that. I checked this and found that it seems to be an issue. I will notify to the product team about this and will keep you posted. At the same time, you could create an entry into the issue tracker.

In this Quickstart in particular some modules are loaded on demand and others don’t. The former ones filter those definitions exported that have no IModule in the contract name as you shown, while the others don’t.

As a workaround, you could load your module setting the InitializationMode to WhenAvailable,  although this is not the ideal scenario. For example:

[ModuleExport(typeof(ModuleB), InitializationMode = InitializationMode.WhenAvailable)]

Please let me know if this helps.

Fernando Antivero

Jul 23, 2010 at 12:18 AM

This looks like the same problem mentioned here : and

Due to the way MEF's DeploymentCatalog appears to work (re-importing types in dependent assemblies, even when they are marked as Shared) we had to do some filtering around this.  We have made some changes in this area that will be in the next drop and filter out only the types that are explicitly in the default exports provider.  We are also working on other approaches that are less intrusive and will hopefully get rid of the need to filter at all.

Thanks again for the feedback,

Michael Puleio