Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-400

Improve error message in SetIdMember when memberMap argument is for a different class

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.4
    • Affects Version/s: 1.3.1
    • Component/s: None
    • None
    • Minor Change

      When SetIdMember is called with a memberMap argument that is for a different class the current error message is too cryptic.

      This can be reproduced using these classes:

      public class B
      {
          public ObjectId Id;
          public int b;
      }
      
      public class C : B
      {
          public int c;
      }
      

      and this code:

      BsonClassMap.RegisterClassMap<C>(cm =>
      {
          cm.AutoMap();
          cm.SetIdMember(cm.GetMemberMap(c => c.Id)); // wrong: Id is in class B, not class C
      });
      

      The call to SetIdMember is incorrect because it is being called when registering class C but Id is defined in class B. SetIdMember should have been called when registering class B instead.

      The current error message "Invalid memberMap." is too cryptic. A better error message would provide more of an explanation of what is wrong.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: