title: MongoDB class mapping
body: <p>I have following data structure</p>
  
  <pre><code>internal class FixtureNodeBase
  {
    public FixtureNodeBase( string name, IEnumerable&lt;FixtureNodeBase&gt; children )
    {
      Name = name;
      Children = children.ToList().AsReadOnly();
    }
  
    public string Name { get; }
  
    public IReadOnlyList&lt;FixtureNodeBase&gt; Children { get; }
  }
  
  internal class FixtureNode : FixtureNodeBase
  {
    public FixtureNode(
      string name,
      string assembly,
      string runnableName,
      IEnumerable&lt;FixtureNodeBase&gt; children )
      : base( name, children )
    {
      Assembly = assembly;
      RunnableName = runnableName;
    }
  
    public string Assembly { get; }
  
    public string RunnableName { get; }
  }
  
  internal class FixtureTree
  {
    public FixtureTree( FixtureNodeBase root )
    {
      Root = root;
    }
  
    public FixtureNodeBase Root { get; }
  }
  
  internal class Build
  {
    public Build( FixtureTree fixtures )
    {
      Fixtures = fixtures;
    }
  
    public FixtureTree Fixtures { get; }
  }
  </code></pre>
  
  <p>for the data structure I use following mapping</p>
  
  <pre><code>BsonClassMap.RegisterClassMap&lt;Build&gt;(
    cm =&gt;
    {
      cm.MapMember( x =&gt; x.Fixtures );
      cm.MapCreator( x =&gt; new Build( x.Fixtures ) );
  } );
  
  BsonClassMap.RegisterClassMap&lt;FixtureTree&gt;(
    cm =&gt;
    {
      cm.MapMember( x =&gt; x.Root );
      cm.MapCreator( x =&gt; new FixtureTree( x.Root ) );
  } );
  
  BsonClassMap.RegisterClassMap&lt;FixtureNodeBase&gt;(
    cm =&gt;
    {
      cm.MapMember( x =&gt; x.Name );
      cm.MapMember( x =&gt; x.Children );
      cm.MapCreator( x =&gt; new FixtureNodeBase( x.Name, x.Children ) );
  } );
  
  BsonClassMap.RegisterClassMap&lt;FixtureNode&gt;(
    cm =&gt;
    {
      cm.MapMember( x =&gt; x.Name );
      cm.MapMember( x =&gt; x.Assembly );
      cm.MapMember( x =&gt; x.RunnableName );
      cm.MapMember( x =&gt; x.Children );
      cm.MapCreator( x =&gt; new FixtureNode( x.Name, x.Assembly, x.RunnableName, x.Children ) );
  } );
  </code></pre>
  
  <p>and it throws the exception for <code>FixtureNode</code> mapping:</p>
  
  <blockquote>
    <p>"System.ArgumentOutOfRangeException : The memberInfo argument must be for class FixtureNode, but was for class FixtureNodeBase."</p>
  </blockquote>
  
  <p>LINQPad file with example can be downloaded from here <a href="http://www.filedropper.com/example_2" rel="nofollow noreferrer">example.linq</a></p>
  
  <p>If you have any ideas, how to fix the issue, please share your idea.</p>