title: MongoDB class has argument but none are configured
body: <p>I have a class with some read only properties that I want to store using mongodb.</p>
  
  <p>User.cs</p>
  
  <pre><code>public class User: ValueObject&lt;User&gt;
      {
          public UserId Id { get; }
          public string Firstname { get; }
          public string Lastname { get; }
  
          public User(UserId id, string firstname, string lastname)
          {
              Id = new UserId(id.Id);
              Firstname = firstname;
              Lastname = lastname;
          }
  
          public User(string id, string firstname, string lastname)
          {
              Id = new UserId(id);
              Firstname = firstname;
              Lastname = lastname;
          }
  
          protected override bool MembersEquals(User other)
          {
              return Id == other.Id &amp;&amp; Firstname == other.Firstname &amp;&amp; Lastname == other.Lastname;
          }
  
          protected override int MembersHashCode()
          {
              return Id.GetHashCode() ^ Firstname.GetHashCode() ^ Lastname.GetHashCode();
          }
      }
  </code></pre>
  
  <p>Class map registration:</p>
  
  <pre><code>BsonClassMap.RegisterClassMap&lt;User&gt;(cm =&gt;
              {
                  cm.AutoMap();
                  cm.MapProperty(user =&gt; user.Id);
                  cm.MapProperty(user =&gt; user.Firstname);
                  cm.MapProperty(user =&gt; user.Lastname);
                  cm.MapCreator(user =&gt; new User(user.Id, user.Firstname, user.Lastname));
              });
  </code></pre>
  
  <p>this class is stored as a subdocument. when i try to store the whole document mongodb driver tell me that the <em>MongoDB.Bson.BsonSerializationException: Creator map for class Box.Domain.User has 3 arguments, but none are configured.</em>. I didn't really understand what does it mean.</p>
  
  <p><strong>NB: the UserId class has a registred serializer</strong></p>
  
  <pre><code>public class UserIdBsonSerializer : SerializerBase&lt;UserId&gt;
      {
          public override UserId Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
          {
              var currentBsonType = context.Reader.GetCurrentBsonType();
              return currentBsonType switch
              {
                  BsonType.String =&gt; new UserId(context.Reader.ReadString()),
                  _ =&gt; throw new NotSupportedException($"Cannot deserialize {currentBsonType} to an UserId")
              };
          }
  
          public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, UserId value)
          {
              context.Writer.WriteString(value.Id);
          }
      }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>ValueObject.cs</p>
  
  <pre><code>public abstract class ValueObject&lt;T&gt; : IEquatable&lt;T&gt;
          where T : ValueObject&lt;T&gt;
      {
          // Verify the value object members equality.
          protected abstract bool MembersEquals(T other);
  
          // Generate a hash code depending on the value object members values.
          protected abstract int MembersHashCode();
  
          #region Equality
          public bool Equals([AllowNull] T other)
          {
              if (ReferenceEquals(other, null))
                  return false;
  
              if (ReferenceEquals(this, other))
                  return true;
  
              return MembersEquals(other);
          }
  
          public override bool Equals(object obj)
          {
              var other = obj as T;
  
              return Equals(other);
          }
  
          public static bool operator ==(ValueObject&lt;T&gt; lhs, ValueObject&lt;T&gt; rhs)
          {
              if (ReferenceEquals(lhs, null) &amp;&amp; ReferenceEquals(rhs, null))
                  return true;
  
              if (ReferenceEquals(lhs, null))
                  return false;
  
              return lhs.Equals(rhs);
          }
  
          public static bool operator !=(ValueObject&lt;T&gt; lhs, ValueObject&lt;T&gt; rhs) =&gt; !(lhs == rhs);
          #endregion
  
          public override int GetHashCode()
          {
              return MembersHashCode();
          }
      }
  </code></pre>
  
  <p>UserId.cs</p>
  
  <pre><code>public class UserId: ValueObject&lt;UserId&gt;
      {
          public string Id { get; }
  
          public UserId(string id)
          {
              if (id.Length &lt; 5)
                  throw new ArgumentException($"user id must be 5 characters length. {id}");
  
              // TODO: Add more validation rules for user id
  
              Id = id;
          }
          protected override bool MembersEquals(UserId other)
          {
              return Id == other.Id;
          }
  
          protected override int MembersHashCode()
          {
              return Id.GetHashCode();
          }
      }
  </code></pre>