MEF 组合异常

发布于 2024-10-05 08:21:36 字数 759 浏览 1 评论 0原文

我收到以下消息的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼痛 2024-10-12 08:21:36

这可能是因为您正在从多个线程使用 CompositionContainer。你是那个吗?

This might be because you are using the CompositionContainer from multiple threads. Are you diong that?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文