title: VB.NET - Custom Serialization and Circular References, is there a clean solution?
body: <p>I'm implementing some custom serialization (to byte array), and have run into a problem handling circular references.</p>
  
  <p>Example:</p>
  
  <pre><code>Class A
    public MyBs as new List(of B)
  End class
  
  Class B
    public MyParent as A
    public MiscInt1 as integer
    public MiscInt2 as integer
  End Class
  </code></pre>
  
  <p>When serializing A, I must serialize each instance of B.</p>
  
  <p>However, I have a problem when serializing B. </p>
  
  <p>How do I record the parent of B without causing an infinite loop? </p>
  
  <p>An idea:</p>
  
  <p>If I know that an instance of B will only ever be serialized through the serialization of an instance of A, then I can handle the setup of the MyParent reference from the instance of A and not even record that information inside the byte buffer for the instance of B</p>
  
  <p>This doesn't feel quite right, but it might be the best solution.</p>
  
  <p>Is there a cleaner way of handling this situation?</p>