Recomposition error when removing a catalog?

May 5, 2010 at 5:06 PM

Hi,

I have a project following the DeploymentCatalogService example that downloads a number of Xap "workspaces" on demand.  One of the workspaces has a number of Views which are UserControls where each one uses MEF to loads its associated ViewModel.  When loading the workspace everything works fine and all of the ViewModels are loaded and associated with the various Views.

When the user logs out of the system I want to go through the aggregate catelog and remove all of the loaded Xap catelogs.   The code looks something like the following:

foreach (var catalog in this.catalogs)
{
    DeploymentCatalogService.aggregateCatalog.Catalogs.Remove(catalog.Value);
}

this.catalogs.Clear();

Where the "catalog" is one of the many loaded  xap files.  When it unloads the workspace where I haven't added any MEF support everything works fine.  When it tries to unload the one workspace that is currently using the MEF to load and associate the ViewModels with the Views I get the following exception:

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

The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced multiple composition errors, with 3 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 'MyApp.Workspaces.Workspace1.Views.View1.ViewModel (ContractName="MyApp.Workspaces.Workspace1.ViewModels.View1Model")' on part 'MyApp.Workspaces.Workspace1.Views.View1'.

2) Change in exports prevented by non-recomposable import 'MyApp.Workspaces.Workspace1.Views.View2.ViewModel (ContractName="MyApp.Workspaces.Workspace1.ViewModels.View2ViewModel")' on part 'MyApp.Workspaces.Workspace1.Views.View2'.

3) Change in exports prevented by non-recomposable import 'MyApp.Workspaces.Workspace1.Views.View3.ViewModel (ContractName="MyApp.Workspaces.Workspace1.ViewModels.View3Model")' on part 'MyApp.Workspaces.Workspace1.Views.View3'."

I have tried with and without using AllowRecomposition=true on the Imports and this is where I am stumped.  I am not sure where else the recomposition might be needed.  What is interesting is this is happening when I am trying to get rid of everything.

Cheers,

Clint

May 6, 2010 at 5:39 PM

Making them recomposable should have fixed. That said, I wonder why you need to do this. Actually, if you want to turn everything off, you should just dispose the container and the catalog.

May 6, 2010 at 5:48 PM

Maybe you should try stopping the web app/ cleaning your solution to see if you have the latest binaries. It may be that you are seeing old binaries before you marked the imports as recomposable?

Glenn

May 7, 2010 at 5:46 AM

I have tried cleaning the whole folder previously.  But I will try again.

Any idea why when trying to remove the catalog this might happen?  I guess I don't understand why anything should be recomposed.  Is MEF trying to replace origninal imports with new ones? Though, I don't know why it would want to create new imports when the objects should be in the state of being torn down?  haveriss mentioned about disposing.  Should I be setting my objects to be IDisposable for some reason?

Cheers,

Clint

May 7, 2010 at 5:54 PM

What I meant is that you should just dispose the container and the catalog instead.

Oct 14, 2010 at 1:24 PM

I have the same issue and I do not want to dispose the container because i use it to load another xap file

Dec 9, 2010 at 6:25 AM

I'm having the same issue. I'm using Prism 4 dll's. How do we get around this? It is trying to recompose the imports when removing from the aggregatecatalog. Even specifying AllowRecomposition = true is not making a difference.

Dec 11, 2010 at 5:06 AM
Edited Dec 14, 2010 at 10:10 AM

Can somebody please let me know why this happens? It's causing a lot of issues for me at the moment.

Dec 28, 2010 at 5:47 AM

I have found a resolution. Here it is.