Imports fail

Jul 22, 2010 at 1:55 PM
Hi, is there any way to import all DLLs within a directory, even though one of the Importcontracts is not met? If I Import IType1 and IType2, and the directorycatalog does not contain IType2 Exports then I get the following error: 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 == "Contracts_1.IType2") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "Contracts_1.IType2".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))', invalid exports may have been rejected. Resulting in: Cannot set import..... What can I do to create a plugin concept that will still compile even if some of the imports cannot be done? Of course I will check, if the desired Export(DLL) is within the directory, once i call it. The goal is, to provide functions, when the plugin-dll is put into the directory. Thanks Jens
Jul 22, 2010 at 7:07 PM

You can do this with your import attribute by setting the AllowDefault property [Import(AllowDefault=true)] which will leave the import a null reference instead of rejecting the part.

Jul 23, 2010 at 1:38 PM

Thank you,

that works fine with a single Import. But ImportMany does not allow this Attribute.

Is there something aequivalent for ImportMany?

 

THX

Jens