Odd BsonReader/BsonWriter bug

Jul 7, 2010 at 2:42 PM
Edited Jul 7, 2010 at 2:51 PM
var testAlbum = new TrackMetaData
                    FilePath = "E:\\Music\\Albums\\Ministry Of Sound - Chilled 1991-2008 (2008) [EAC @ 320 MP3](oan)\\Chilled 1991-2008 Disc 1 mp3\\13 - Tim “Love” Lee - One Night Samba.mp3";

           var ms = new MemoryStream();

           using (var bsonWriter = new BsonWriter(ms))
               new JsonSerializer().Serialize(bsonWriter, testAlbum);
               ms.Seek(0, SeekOrigin.Begin);
               new JsonSerializer().Deserialize<TrackMetaData>(new BsonReader(ms));
The error is: System.ArgumentOutOfRangeException : Unexpected BsonType value: 68 Parameter name: type Anyone know what's going on? Using JsonCovert the string can be serialized/deserialized fine.
Jul 12, 2010 at 11:53 PM

There is a fairly serious bug in the BsonReader class when handling multi-byte characters (i.e. the quotation mark character at index 128 in your string).  I recently debugged this problem and submitted a patch:


If you don't want to wait for the next official release, you can apply my patch to 3.5 R7.  Or take your chances with the SVN head.  :-)