That helps.
On line 255, I was trying to determine if it was a dictionary so I could specify dictionary options, but I've removed that, and the dict field gets serialized by the DictionarySerializer<string,object> with the null passed as the options, and it still puts the discriminator in there...the serialized data looks exactly the same.
I tried using the ObjectSerializer like you suggested, but that doesn't work at all either:
System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at System.String.Format(String format, Object arg0)
at MongoDB.Bson.Serialization.Serializers.ObjectSerializer.Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) in C:\work\10gen\mongodb\mongo-csharp-driver\Bson\Serialization\Serializers\ObjectSerializer.cs:line 66
The _t and _v fields are because the DictionarySerializer is serializing this field as a document, and this seems to be the default behavior. The only way I can really get this to work is to do this to advance it through the _t field and have the DictionarySerializer.Deserializer called when I should be to the value of the _v field:
bsonReader.ReadStartDocument();
bsonReader.ReadName(); // reads name _t
bsonReader.ReadString(); // reads value of _t
bsonReader.ReadName(); // reads name of _v
object propVal = serializer.Deserialize(bsonReader, actualType, options); // reads value of _v
bsonReader.ReadEndDocument();
BinderHelper.SetMemberValue(value, propName, propVal);
That seems like a hack to me, but it works.
I'm advancing through the reader starting on line 147. I don't really understand why I have to do this for a dictionary but don't have to do this for any other types.