JamesNK/Newtonsoft.Json — pull request #383 by spadfield (2014-09-24 17:55:08+00:00)
Title: Fix InvalidCastException when deserializing a GUID from BSON.

Issue: When attempting to deserialize a GUID from BSON, an exception is thrown by the JsonWriter class.

```
System.InvalidCastException : Unable to cast object of type 'System.Guid' to type 'System.Byte[]'.
at Newtonsoft.Json.JsonWriter.WriteToken(JsonReader reader, Int32 initialDepth, Boolean writeChildren, Boolean writeDateConstructorAsDate) in JsonWriter.cs: line 555
at Newtonsoft.Json.JsonWriter.WriteToken(JsonReader reader, Boolean writeChildren, Boolean writeDateConstructorAsDate) in JsonWriter.cs: line 463
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateJObject(JsonReader reader) in JsonSerializerInternalReader.cs: line 251
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) in JsonSerializerInternalReader.cs: line 426
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) in JsonSerializerInternalReader.cs: line 280
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) in JsonSerializerInternalReader.cs: line 186
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) in JsonSerializer.cs: line 710
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) in JsonSerializer.cs: line 689
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader) in JsonSerializer.cs: line 653
at Newtonsoft.Json.Tests.Bson.BsonReaderTests.DeserializeBsonDocumentWithGuid() in BsonReaderTests.cs: line 1727
```

To reproduce:
```
var stream = new MemoryStream();
serializer.Serialize(new BsonWriter(stream), new[] { Guid.NewGuid() });
stream.Position = 0;
serializer.Deserialize(new BsonReader(stream));
```

All unit tests still pass.