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

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • 1.4
    • 1.3.1
    • None
    • None
    • Minor Change

    Description

      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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: