Question

Receiving the following upon call to hostContainer.ComposeParts():

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.

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

Resulting in: Cannot set import 'ModAppWorks.Host.DataHandler (ContractName="ModLibrary.IDataHandler")' on part 'ModAppWorks.Host'. Element: ModAppWorks.Host.DataHandler (ContractName="ModLibrary.IDataHandler") --> ModAppWorks.Host

Source=System.ComponentModel.Composition StackTrace: at System.ComponentModel.Composition.CompositionResult.ThrowOnErrors(AtomicComposition atomicComposition) at System.ComponentModel.Composition.Hosting.ComposablePartExportProvider.Compose(CompositionBatch batch) at System.ComponentModel.Composition.Hosting.CompositionContainer.Compose(CompositionBatch batch) at System.ComponentModel.Composition.AttributedModelServices.ComposeParts(CompositionContainer container, Object[] attributedParts) at ModAppWorks.Host.Compose() in C:\Projects\ModAppWorks_2\HostProgram.cs:line 83 at ModAppWorks.Host.Run() in C:\Projects\ModAppWorks_2\HostProgram.cs:line 49 at ModAppWorks.Program.Main() in C:\Projects\ModAppWorks_2\HostProgram.cs:line 25 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

Import snippet:

[Import(typeof(IDataHandler))]
public Lazy<IDataHandler> DataHandler { get; set; }

However, the DataHandler is defined as such:

[Export(typeof(IDataHandler))]
public class DataAgent : DataProvider<SqlConnection, SqlDataReader>, IDataHandler
{
    // contains an empty public ctor passing ctor parameters to DataProvider
}

DataProvider is an abstract class that also inherits IDataHandler and actually implements the IDataHandler interface. Also, builds are written directly to an \Extensions directory for the Host app.

Any suggestions as to what I am doing wrong?

Was it helpful?

Solution

I began to suspect that the constructor cannot call a base constructor with parameters. I removed the call to : base(param1, param2) and the class will import.

Edit

Okay, made some more tests with this and it seems that, yes, your class can provide parameters to a base constructor as long as the base class is not inheriting the part to be imported to the host.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top