Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MEF CompositionException

Tags:

mef

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!

like image 954
Serhiy Avatar asked Jun 11 '26 13:06

Serhiy


1 Answers

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

like image 121
Daniel Plaisted Avatar answered Jun 20 '26 20:06

Daniel Plaisted



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!