Anyone know what might cause this unusual error?

Aug 30, 2009 at 2:06 AM

Unusual to me anyway.

This is all in preview 6.

The error is below. AFAIK, I am not doing any recompositoin. I am adding to the container, but I've walkied this very carefully and I think its all the same DLL .I've close and reopened VS, looked for out of date assemblies and cleaned hte solutions.

There are two wolutions in play here. The entry solution contains about 40 projects and is the core of the system. This one is in VS 2008 targetting 3.5. The second solution is a VS2010 solutoin so I can play with preprocessed templates. This project is targetting .NET 3.5. Its all on Win 7 64 bit. I've checked and double checked for bad targets and incorrect CPU targets, but those normally give a different error.

This used to work. It stopped working and I'm not sure exactly what I did that went south. I did a full dayof refactoring, so rolling back the code to try to sort this out really isn't an option.

So, any hints as to what kinds of things to look for with this error would be greatly appreciated.

 

System.ComponentModel.Composition.ChangeRejectedException was unhandled
  Message="The composition remains unchanged. The changes were rejected because of the following error(s): The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.\r\n\r\n1) Change in exports prevented by non-recomposable import 'AppVenture.TemplateHarness.TemplateHarness._processExports (ContractName=\"AppVenture.Common.IProcessWrapper\")' on part 'AppVenture.TemplateHarness.TemplateHarness'.\r\n"
  Source="System.ComponentModel.Composition"
  StackTrace:
       at System.ComponentModel.Composition.CompositionResult.ThrowOnErrors(AtomicComposition atomicComposition) in c:\Users\Kathleen\Downloads\MEF_Preview_6\MEF_Preview_6\src\ComponentModel\System\ComponentModel\Composition\CompositionResult.cs:line 84
       at System.ComponentModel.Composition.Hosting.ExportProvider.OnExportsChanging(ExportsChangeEventArgs e) in c:\Users\Kathleen\Downloads\MEF_Preview_6\MEF_Preview_6\src\ComponentModel\System\ComponentModel\Composition\Hosting\ExportProvider.cs:line 200
       at System.ComponentModel.Composition.Hosting.CatalogExportProvider.OnCatalogChanging(Object sender, ComposablePartCatalogChangeEventArgs e) in c:\Users\Kathleen\Downloads\MEF_Preview_6\MEF_Preview_6\src\ComponentModel\System\ComponentModel\Composition\Hosting\CatalogExportProvider.cs:line 301
       at System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.OnChanging(Object sender, ComposablePartCatalogChangeEventArgs e) in c:\Users\Kathleen\Downloads\MEF_Preview_6\MEF_Preview_6\src\ComponentModel\System\ComponentModel\Composition\Hosting\ComposablePartCatalogCollection.cs:line 352
       at System.ComponentModel.Composition.Hosting.AggregateCatalog.OnChanging(ComposablePartCatalogChangeEventArgs e) in c:\Users\Kathleen\Downloads\MEF_Preview_6\MEF_Preview_6\src\ComponentModel\System\ComponentModel\Composition\Hosting\AggregateCatalog.cs:line 219
       at System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.RaiseChangingEvent(Lazy`1 addedDefinitions, Lazy`1 removedDefinitions, AtomicComposition atomicComposition) in c:\Users\Kathleen\Downloads\MEF_Preview_6\MEF_Preview_6\src\ComponentModel\System\ComponentModel\Composition\Hosting\ComposablePartCatalogCollection.cs:line 344
       at System.ComponentModel.Composition.Hosting.ComposablePartCatalogCollection.Add(ComposablePartCatalog item) in c:\Users\Kathleen\Downloads\MEF_Preview_6\MEF_Preview_6\src\ComponentModel\System\ComponentModel\Composition\Hosting\ComposablePartCatalogCollection.cs:line 62
       at AppVenture.Common.ExportingCompositionContainer.AddAssembly(String assemblyName) in C:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator 2008 MEF 6\T4Host\Source\CSharp\DefaultCommon\ExportingCompositionContainer.cs:line 161
       at AppVenture.Common.ExportingCompositionContainer.<AddAssemblies>b__17(String x) in C:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator 2008 MEF 6\T4Host\Source\CSharp\DefaultCommon\ExportingCompositionContainer.cs:line 172
       at System.Collections.Generic.List`1.ForEach(Action`1 action)
       at AppVenture.Common.ExportingCompositionContainer.AddAssemblies(IEnumerable`1 assemblyNames) in C:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator 2008 MEF 6\T4Host\Source\CSharp\DefaultCommon\ExportingCompositionContainer.cs:line 172
       at AppVenture.Common.ExportingCompositionContainer.AddDirectories(IEnumerable`1 dirs) in C:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator 2008 MEF 6\T4Host\Source\CSharp\DefaultCommon\ExportingCompositionContainer.cs:line 203
       at AppVenture.TemplateHarness.TemplateHarness.AddServiceLocations(String baseTemplatePath, IEnumerable`1 paths) in C:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator 2008 MEF 6\T4Host\Source\CSharp\TemplateHarness\TemplateHarness.cs:line 53
       at AppVenture.TemplateHarness.TemplateHarnessHelpers.ExecuteGeneration() in C:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator 2008 MEF 6\T4Host\Source\CSharp\TemplateHarness\TemplateHarnessHelpers.cs:line 99
       at AppVenture.CmdGeneration.GenerationRun.Run() in C:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator 2008 MEF 6\T4Host\Source\UserInterfaces\CmdGeneration\Program.cs:line 211
       at AppVenture.CmdGeneration.Program.Main(String[] args) in C:\Users\Kathleen\Current Projects\CodeGen\AppVentureCommunityGenerator 2008 MEF 6\T4Host\Source\UserInterfaces\CmdGeneration\Program.cs:line 47
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

Aug 30, 2009 at 8:58 PM
Edited Aug 30, 2009 at 9:00 PM

This is stable composition kicking in and preventing changes in the catalog from being accepted. If you look in the exception it says the root cause is that TemplateHarness._processExports is not recomposable. Set the AllowRecomposition property of that import to true.

I am guessing that when AddAssembly is called, new IProcessWrappers are showing up and getting added to the container. That kicks off recomposition. However, because _processExports is not recomposable it is basically saying to MEF, "DON'T ALLOW any changes to any IProcessWrapper contracts". Stable composition not only causes parts that cannot be satisfied to be rejected, it also causes parts that would involate the state of composition to be rejected. Thus a new IProcessWrapper is violating that state currently because of the AllowRecomposition setting.

Now one way to work around making the import recomposable, is to collect all the parts you are adding before you actaully add them to the container by adding them all to an aggregate catalog first, then creating the container with that aggregate.  Currently it appears that you have the container created, and then you keep adding catalogs which forces recomposition each time.

HTH

Glenn

Aug 31, 2009 at 2:58 PM

Thanks Glenn.