MEF 组合异常
我收到以下消息的 CompositionException 异常: “‘SomeService’类型的 ComposablePart 无法重新组合,因为它处于无效状态。只有在已经完全预览或组合后才能重新组合。”
这段代码抛出异常:
public class SomeService : ISomeService
{
[Import(typeof(ISomeType))]
public ISomeType SomeType { get; set; }
public SomeService()
{
Container.ComposeParts(this);
}
}
但是一切都很好:
public class SomeService : ISomeService
{
[Import(typeof(ISomeType))]
public ISomeType SomeType { get; set; }
public SomeService()
{
this.SomeType = Container.GetExportedValue<ISomeType>();
}
}
我在其他地方有这个代码“Container.ComposeParts(this)”并且它可以工作,但在这里却不行。
在谷歌搜索“无法重组,因为它处于无效状态”后,我没有发现任何有趣的东西。
这个消息是什么意思? 谢谢你!
I have the CompositionException exception with this message:
"The ComposablePart of type 'SomeService' cannot be recomposed because it is in an invalid state. It can only be recomposed if it has already been fully previewed or composed."
Exception is thrown by this code:
public class SomeService : ISomeService
{
[Import(typeof(ISomeType))]
public ISomeType SomeType { get; set; }
public SomeService()
{
Container.ComposeParts(this);
}
}
but everything fine with this:
public class SomeService : ISomeService
{
[Import(typeof(ISomeType))]
public ISomeType SomeType { get; set; }
public SomeService()
{
this.SomeType = Container.GetExportedValue<ISomeType>();
}
}
I have this code "Container.ComposeParts(this)" in other places and it works but here it doesn't.
I didn't found nothing interesting after googling with "cannot be recomposed because it is in an invalid state".
What does this message mean?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是因为您正在从多个线程使用 CompositionContainer。你是那个吗?
This might be because you are using the CompositionContainer from multiple threads. Are you diong that?