提前感谢你的帮助。我有以下导出的部分:
[Export (typeof(INewComponent))] // orignally tried just [Export} here and importing NewComponent below
public class NewComponent : INewComponent
{
// does stuff including an import
}
控制台测试程序导入以上内容:
public class Program
{
[Import] // have tried variations on importing "NewComponent NewComponent" etc
public INewComponent NewComponent
{
get;
set;
}
public static void Main(string[] args)
{
var p = new Program();
var catalog = new AssemblyCatalog(typeof(Program).Assembly);
var container = new CompositionContainer(catalog);
container.ComposeParts(p);
}
组合因这些组合异常而失败(我删除了命名空间以保护有罪:)):
1) 没有找到与约束匹配的有效导出 '((exportDefinition.ContractName == "INewComponent") AndAlso (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") AndAlso "INewComponent".Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity) "))))',无效的导出可能已被拒绝。
如果我像这样在主程序中进行组合,则组合可以成功运行:
public class Program
{
public static void Main(string[] args)
{
INewComponent newComponent = new NewComponent();
var catalog = new AssemblyCatalog(typeof(Program).Assembly);
var container = new CompositionContainer(catalog);
container.ComposeParts(newComponent);
}
}
谢谢你