title: GetExportedValue cannot be called before prerequisite import has been set
body: <p>We are using <strong>MEF</strong> in a <strong>WPF</strong> application. </p>
  
  <p>And we are getting this <strong>error</strong>:</p>
  
  <blockquote>
    <p>GetExportedValue cannot be called before prerequisite import 'MyNamespace.MyMainClass..ctor (Parameter="myParameter", ContractName="IContractInterface")' has been set.</p>
  </blockquote>
  
  <p>I am <strong>not using threads</strong>, I read sometimes this error happens with multiple threads, however just in case I created the composition container passing the "thread safe" parameter in true</p>
  
  <pre><code>var container = new CompositionContainer(catalog, true);
  </code></pre>
  
  <p><strong>The Code</strong> I have is:</p>
  
  <p>My simplified Main Class code is: (The idea is that if there are not import for IMySubClass, I will use a default Implementation, that is why I create it on the "OmImportsSatisfied" method and satisfy its imports.)</p>
  
  <p><strong>MyMainClass C#</strong></p>
  
  <pre><code>[Export(typeof(IMyInterface)]
  public class MyMainClass: IPartImportsSatisfiedNotification, IMyInterface
  {
      [Import]
      public IContainer Container { get; private set; }
  
      [Import(AllowDefault = true)]
      public IMySubClass MySubClass { get; set; }
  
      [ImportingConstructor]
      public MyMainClass([Import(AllowDefault = true)] IContractInterface myParameter= null)
          : this()
      {
          if (myParameter!= null)
          {
              //Do Something with myParameter
          }            
      }
  
      public void OnImportsSatisfied()
      {
          if (MySubClass == null)
          {
              MySubClass = new MySubClass();
              Container.SatisfyImportsOnce(MySubClass);
          }
  
          //Some other stuff
       }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>MySubClass C#</strong></p>
  
  <pre><code>public class MySubClass : IPartImportsSatisfiedNotification, IMySubClass
  {
      [ImportMany]
      public Lazy&lt;IMyAttributeInterface, IMyAttributeInterfaceMetadata&gt;[] Exports { get; set; }
  
      public void OnImportsSatisfied()
      {
          foreach (var export in Exports)
          {
              var value = export.Value; //Here it throws the Exception
              //Do something.
          }
      }
  </code></pre>
  
  <p><strong>The error is thrown in MySubClass, inside the OnImportSatisfied method on the line</strong>:</p>
  
  <pre><code>var value = export.Value;
  </code></pre>
  
  <p>However when I debug the ImportConstructor of MyMainClass is called successfully, and <strong>myParameter</strong> is injected and used. Afterwards the OnImportsSatisfied method is called <strong>and I get the error.</strong></p>
  
  <hr>
  
  <p>The Exports list from my Subclass comes from properties in other classes that have the Attribute "MyExportAttribute". I don't have much experience creating Export Attributes, so here is the code in case the problem is coming from it.</p>
  
  <p><strong>Export Attribute</strong></p>
  
  <pre><code>public interface IMyAttributeInterfaceMetadata
  {
      string Property1 { get; }
      string Property2 { get; }
  }
  
  [MetadataAttribute]
  [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
  public class MyExportAttribute : ExportAttribute, IMyAttributeInterfaceMetadata
  {
      string Property1 { get; }
      string Property2 { get; }
  
      public MyExportAttribute(string property1, string property2)
          : base(typeof(IMyAttributeInterface))
      {
          Property1 = property1;
          Property2 = property2;
      }
  }
  </code></pre>