Dynamic Module Loading with MEF in SL5

Dec 12, 2011 at 8:04 PM

Does anyone have Prism 4 working with SL5 and loading modules dynamically using MEF?

Pointers / Warnings / How tos? 

Dec 12, 2011 at 8:39 PM

I'm using RiaServices/Prism4/Mef/EntityFramework and have simmilar problem.

After recompilation of Prism4 Library for SL5, I've set up 'Copy Local' to 'True' for MefExtensions in all my client projects.

Then I've removed all Bin/Obj folders and xaps (from ClientBin, server side) manually.

The application now starting  without error message related to MEF, but there is another complex error message :

 

The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced multiple composition errors, with 9 root causes. The root causes are provided below. Review the CompositionException.Errors property for more detailed information.

1) Change in exports prevented by non-recomposable import 'MyProject.Shell.ModuleManager (ContractName="Microsoft.Practices.Prism.Modularity.IModuleManager")' on part 'MyProject.Shell'.

2) Change in exports prevented by non-recomposable import 'MyProject.Shell.RegionManager (ContractName="Microsoft.Practices.Prism.Regions.IRegionManager")' on part 'MyProject.Shell'.

3) Change in exports prevented by non-recomposable import 'MyProject.Shell.EventAggregator (ContractName="Microsoft.Practices.Prism.Events.IEventAggregator")' on part 'MyProject.Shell'.

4) Change in exports prevented by non-recomposable import 'MyProject.Shell.ModuleManager (ContractName="Microsoft.Practices.Prism.Modularity.IModuleManager")' on part 'MyProject.Shell'.

5) Change in exports prevented by non-recomposable import 'MyProject.Shell.RegionManager (ContractName="Microsoft.Practices.Prism.Regions.IRegionManager")' on part 'MyMyProject.Shell'.

6) Change in exports prevented by non-recomposable import 'MyProject.Shell.EventAggregator (ContractName="Microsoft.Practices.Prism.Events.IEventAggregator")' on part 'MyProject.Shell'.

7) Change in exports prevented by non-recomposable import 'MyProject.Shell.ModuleManager (ContractName="Microsoft.Practices.Prism.Modularity.IModuleManager")' on part 'MyProject.Shell'.

8) Change in exports prevented by non-recomposable import 'MyProject.Shell.RegionManager (ContractName="Microsoft.Practices.Prism.Regions.IRegionManager")' on part 'MyProject.Shell'.

9) Change in exports prevented by non-recomposable import 'MyProject.Shell.EventAggregator (ContractName="Microsoft.Practices.Prism.Events.IEventAggregator")' on part 'MyProject.Shell'.

 

Dec 12, 2011 at 10:38 PM

Personally, I set copy local to true for the MefExtension DLL in the shell project and then ensure it is false in all other projects.

As for your particular error, it seems that you are attempting to read the same assembly in multiple times.  Either in your boot strapper, or through a reference in an assembly that your are loading into your mef catalogs.  

The parts in the error message are part of the Microsoft.Practices.Prism.dll

Dec 13, 2011 at 2:24 AM

Well, I solved my problem.  

Had to ensure that all referenced assemblies within my dynamically loaded  XAP were compiled against SL5.  

This included:

System.Windows.Controls.Toolkit (September 2011 SL 5 Toolkit)

System.Windows.Interactivity (Expression SL 5 Preview)

Microsoft.Expression.Interactions (Expression SL 5 Preview)

Any third party DLL's you downloaded and installed because they did something cool.... had to be recompiled for SL 5.

 

Dec 17, 2011 at 8:49 AM

Finally solved !

The solution was simple - I have several projects and names of two are: 'MyProject' (this is the main project) and 'MyProject.Main'.

'Copy Local = True' for 'MefExtensions' shoud be set up for 'MyProject', not for 'MyProject.Main' ;)