I've already posted this to Microsoft Silverlight forum but I just noticed that this could be better place to get answers :)
I have done an test application using MEF and DeploymentCatalog. My purpose was to test if I can create a main application that composes and displays several independently developed applications. Applications are distributed in xap-files and loaded with
DeploymentCatalog. Every application exports its user interface to main application with MEF. Applications should not know anything about each other. All communication between applications, if any, is done by using CompositePresentationEvents. Applications
are possibly using different versions of third party components.
Composer implementation in portal looks like this:
public void Compose()
var catalog = new AggregateCatalog();
var container = new CompositionContainer(catalog);
private void AddLocalPackageToCatalog(AggregateCatalog catalog)
private static void AddExternalPackagesToCatalog(AggregateCatalog catalog)
private static void DownloadPackageToCatalog(AggregateCatalog catalog, string uri)
DeploymentCatalog deploymentCatalog = new DeploymentCatalog(uri);
deploymentCatalog.DownloadCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(deploymentCatalog_DownloadCompleted);
static void deploymentCatalog_DownloadCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
if (e.Error != null)
Everything works fine if composed applications are using the same version of referenced assemblies. When applications use different version of the same assembly (and that assembly is in xap-files) I get the following exception when the second xap is loaded.
Exception is thrown before the DownloadCompleted-event is raised:
Message=Could not load file or assembly 'ExternalLibrary, Version=188.8.131.52, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest.
(Exception from HRESULT: 0x80131053)
kohteessa System.Reflection.RuntimeAssembly.nLoadImage(Byte rawAssembly, Byte rawSymbolStore, Evidence evidence, StackCrawlMark& stackMark, Boolean fIntrospection, SecurityContextSource securityContextSource)
kohteessa System.Reflection.Assembly.Load(Byte rawAssembly)
That ExternalLibrary is actually a Silverlight Class Library I've made myself for test purposes. It simulates third party component. Both xap files (ExternalApplication.xap and ExternalApplication2.xap) contain different version of ExternalLibrary (184.108.40.206
and 220.127.116.11). I have also modified an API between versions. It seems that xap files cannot contain different version of same assembly if you use DeploymentCatalog.
I've also tried to remove the first DeploymentCatalog from CompositionContainer and dispose it before loading the other xap, but I still receive the same exception. I've also removed the CompositionContainer so that application just loads those xap files
without composition. Still the same exception.
Is there any way to remove all assemblies loaded earlier with DeploymentCatalog before loading the second xap? Some other ideas how to solve this problem? I think it is quite annoying limitation in otherwise great system.