Silverlight Modularity with MEF Behavior Change - exception

Topics: Prism v4 - Silverlight 4
Aug 23, 2010 at 6:01 PM
Edited Aug 23, 2010 at 6:03 PM

After upgrading my project to the latest release, I started receiving error messages like this when loading a module (this one is actually from the ModularityWithMef quickstart, repro instructions below):

"The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced multiple composition errors, with 10 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 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager.MefXapModuleTypeLoader (ContractName="Microsoft.Practices.Prism.MefExtensions.Modularity.MefXapModuleTypeLoader")' on part 'Microsoft.Practices.Prism.MefExtensions.Modularity.MefModuleManager'.


I've tracked it down to the fact that my projects have Copy Local set to True on all the Prism/MEF references. When my Shell loads, everything loads correctly. The moment I load a module with the module manager, when the module loading is finished I receive the above error message.

This can be reproduced easily:

In the ModularityWithMef quickstart sample, change the following references in ModuleB to Copy Local = True:
* Microsoft.Practices.Prism
* Microsoft.Practices.Prism.MefExtensions

When ModuleB loads, you'll get the above error.

In the previous drop of Prism, this doesn't happen. You can take the same quickstart sample and change the same references, and it'll work fine.

It makes sense for Copy Local to be False on shared libraries so the XAPs aren't larger than they need to be, however since this is the default value when you browse to a DLL to add a reference, anyone using modularity will encounter this issue. And it's not an easy issue to track down.

Aug 23, 2010 at 6:05 PM

Sorry, just saw there was an issue tracker. I created a new issue there.

Dec 28, 2010 at 3:57 PM

Microsoft.Practices.Prism.MefExtensions: Copy Local=False.

Dec 28, 2010 at 4:05 PM

Yes, I said that in my description above. This also applies to any assembly shared across different modules that has any imports or exports in it. You have to guarantee that all shared assemblies (MefExtensions or your own) have CopyLocal set to false.