开发者

Problem with complex derived type importing to MEF Host app

开发者 https://www.devze.com 2023-01-29 21:41 出处:网络
Receiving the following upon call to hostContainer.ComposeParts(): System.ComponentModel.Composition.ChangeRejectedException

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消