title: How can I serialize an object that has an interface as a property?
body: <p>I have 2 interfaces IA and IB.</p>
  
  <pre><code>public interface IA
  {
      IB InterfaceB { get; set;  }
  }
  
  public interface IB
  {
      IA InterfaceA { get; set;  }
  
      void SetIA(IA value);
  }
  </code></pre>
  
  <p>Each interfaces references the other.  </p>
  
  <p>I am trying to serialize ClassA as defined below.</p>
  
  <pre><code>[Serializable]
  public class ClassA : IA
  {
      public IB InterfaceB { get; set; }
  
      public ClassA()
      {
          // Call outside function to get Interface B
          IB interfaceB = Program.GetInsanceForIB();
  
          // Set IB to have A
          interfaceB.SetIA(this);
      }
  }
  
  [Serializable]
  public class ClassB : IB
  {
      public IA InterfaceA { get; set; }
  
      public void SetIA(IA value)
      {
          this.InterfaceA = value as ClassA;
      }
  }
  </code></pre>
  
  <p>I get an error when I try too serialize because the 2 properties are interfaces. I want to serialize the properties.</p>
  
  <p>How would I get around this?</p>
  
  <p>I need to have references in each interface to the other.  And I need to be able to serialize the class back and forth.</p>