C# Driver
  1. C# Driver
  2. CSHARP-263

Deserialization of array that was serialized with nominalType object fails due to lack of type information

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major - P3 Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 1.2
    • Component/s: None
    • Labels:
      None
    • Operating System:
      ALL
    • # Replies:
      2
    • Last comment by Customer:
      false

      Description

      Can reproduce using this class:

      public class C

      { public ObjectId Id; public object Obj; }

      and this code:

      collection.RemoveAll();
      var c = new C { Obj = new int[]

      { 1, 2, 3 }

      };
      collection.Insert(c);

      var r = collection.FindOneAs<C>(); // fails

        Issue Links

          Activity

          Hide
          Robert Stam
          added a comment -

          Running the above code results in the following document being inserted into the database:

          > db.test.find()

          { "_id" : ObjectId("4e170e44e447ad78a009cf75"), "Obj" : [ 1, 2, 3 ] }

          >

          The question is, what could this be serialized as? Perhaps:

          > db.test.find()
          { "_id" : ObjectId("4e170e44e447ad78a009cf75"), "Obj" :

          { "_t" : "System.Int32[]", "_v" : [ 1, 2, 3 ] }

          }
          >

          Not very cross platform... (includes .NET type name).

          A very similar problem occurs with Dictionaries:

          var c = new C { Obj = new Dictionary<string, int> {

          { "a", 1 }

          ,

          { "b", 2 }

          ,

          { "c", 3 }

          } };
          collection.Insert(c);

          which serializes as:

          > db.test.find()
          { "_id" : ObjectId("4e171014e447adbd34b71987"), "Obj" :

          { "a" : 1, "b" : 2, "c" : 3 }

          }
          >

          And also can't be deserialized due to the lack of type information.

          Another question is whether you should get back an instance of the exact same type as you started with. If not, these two examples could simply be deserialized as a BsonArray and a BsonDocument, but that's different than what you started with (an Int32[] and a Dictionary<string, int>).

          Show
          Robert Stam
          added a comment - Running the above code results in the following document being inserted into the database: > db.test.find() { "_id" : ObjectId("4e170e44e447ad78a009cf75"), "Obj" : [ 1, 2, 3 ] } > The question is, what could this be serialized as? Perhaps: > db.test.find() { "_id" : ObjectId("4e170e44e447ad78a009cf75"), "Obj" : { "_t" : "System.Int32[]", "_v" : [ 1, 2, 3 ] } } > Not very cross platform... (includes .NET type name). A very similar problem occurs with Dictionaries: var c = new C { Obj = new Dictionary<string, int> { { "a", 1 } , { "b", 2 } , { "c", 3 } } }; collection.Insert(c); which serializes as: > db.test.find() { "_id" : ObjectId("4e171014e447adbd34b71987"), "Obj" : { "a" : 1, "b" : 2, "c" : 3 } } > And also can't be deserialized due to the lack of type information. Another question is whether you should get back an instance of the exact same type as you started with. If not, these two examples could simply be deserialized as a BsonArray and a BsonDocument, but that's different than what you started with (an Int32[] and a Dictionary<string, int>).
          Hide
          Robert Stam
          added a comment -

          Created a new issue CSHARP-301 for Dictionary so that this issue can be closed for arrays.

          Show
          Robert Stam
          added a comment - Created a new issue CSHARP-301 for Dictionary so that this issue can be closed for arrays.

            People

            • Assignee:
              Robert Stam
              Reporter:
              Robert Stam
              Participants:
              Last commenter:
              Craig Wilson
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since reply:
                2 years, 36 weeks, 3 days ago