views:

115

answers:

2

Can anybody explain this error 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.

1) No valid exports were found that match the constraint '((exportDefinition.ContractName == "Silverbits.ApplicationServices.ApplicationServicesManager") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "Silverbits.ApplicationServices.ApplicationServicesManager".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))', invalid exports may have been rejected.

Resulting in: Cannot set import 'Silverbits.Applications.SilverbitsApplication.ApplicationServices (ContractName="Silverbits.ApplicationServices.ApplicationServicesManager")' on part 'Framework.App'. Element: Silverbits.Applications.SilverbitsApplication.ApplicationServices (ContractName="Silverbits.ApplicationServices.ApplicationServicesManager") --> Framwork.App

+1  A: 

It's looking for something like this:

[Export]
public class ApplicationServicesManager
{
}

or like this:

public class SomeClass
{
    [Export]
    public ApplicationServicesManager AppServices { get; private set; }
}

But it can't find one in the scope of your provided exports. If you're Exporting it from a property or field, make sure the object exporting it has been composed with the container. If it's a class export and the class is present in another assembly, make sure the assembly is in the container's catalog.

Dan Bryant
I'm using Silverlight 4.0 so I'm not dealing with catalog's, rather I am using the suggested method:CompositionInitializer.SatisfyImports(this);
cmaduro
BTW That still does not solve my problem, as I have exported the ApplicationServicesManager. It's a class in another assembly, but is it included in the xap file, so it should resolve.
cmaduro
SatisfyImports will use an implicitly created global container with a standard catalog, but it should hopefully be set up to use every assembly in the XAP to look for exports; I haven't used MEF with Silverlight, so I'm not entirely sure. In any case, the error is definitely a failure to resolve the Export. I've seen this problem when my class exporting a service as a property wasn't properly composed in the container I was using.
Dan Bryant
A: 

While the ApplicationServicesManager class may be available and marked with an [Export] attribute, this part may still have been rejected because it has itself imports which cannot be satisfied.

Take a look at the section Diagnosing Composition problems in the MEF documentation.

Wim Coenen