[CSHARP-277] C# Driver does not Deserialize System.Drawing.Size Created: 21/Jul/11 Updated: 02/Apr/15 Resolved: 12/Sep/11 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Feature Request |
| Affects Version/s: | 1.1 |
| Fix Version/s: | 1.2 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Joseph A Freeman | Assignee: | Sridhar Nanjundeswaran |
| Resolution: | Done | Votes: | 0 |
| Labels: | serialization | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
.Net 4 |
||
| Description |
|
System.Drawing.Size objects are serialized properly, but not deserialized due to how System.Drawing.Size is constructed. We wrote a custom Serializer to fix this: public class SizeSerializer : IBsonSerializer public object Deserialize(global::MongoDB.Bson.IO.BsonReader bsonReader, Type nominalType, IBsonSerializationOptions options) { if (nominalType != typeof(System.Drawing.Size)) throw new ArgumentException("Cannot serialize anything but System.Drawing.Size"); var doc = MongoDBBson.BsonDocument.ReadFrom(bsonReader); return new System.Drawing.Size(doc["Width"].AsInt32, doc["Height"].AsInt32); }public bool GetDocumentId(object document, out object id, out IIdGenerator idGenerator) { throw new NotImplementedException(); }public void Serialize(global::MongoDB.Bson.IO.BsonWriter bsonWriter, Type nominalType, object value, IBsonSerializationOptions options) { if (nominalType != typeof(System.Drawing.Size)) throw new ArgumentException("Cannot serialize anything but System.Drawing.Size"); var ser = new BsonClassMapSerializer(); ser.Serialize(bsonWriter, nominalType, value, options); } public void SetDocumentId(object document, object id) { throw new NotImplementedException(); } } |
| Comments |
| Comment by Sridhar Nanjundeswaran [ 12/Sep/11 ] |
|
Added custom serializer and register |
| Comment by Joseph A Freeman [ 22/Jul/11 ] |
|
Great, thanks! |
| Comment by Robert Stam [ 22/Jul/11 ] |
|
Sorry. I jumped to the conclusion that it was a .NET 4 datatype without even thinking about it because in the Details section you listed .NET 4 as the environment. I am rescheduling this for version 1.2 of the driver. It's hard to find all the .NET types that people would like to serialize, so let us know if there are more. Lots of them will serialize anyway using the AutoMap feature of BsonClassMapSerializer, but some (like this one) need special treatment. |
| Comment by Joseph A Freeman [ 22/Jul/11 ] |
|
System.Drawing.Size is not a .Net 4 feature (1.1?). I ran the same test in a 3.5 environment and the c# driver still does not deserialize System.Drawing.Size objects. |
| Comment by Robert Stam [ 22/Jul/11 ] |
|
Right now we are targeting .NET 3.5 as the required .NET version. At some point we will begin to add .NET 4 features. We haven't quite decided how to do this. Options include: factoring the .NET 4 specific features into a separate DLL that users of .NET 3.5 would not reference, using conditional compilation to produce two versions of the driver, or making .NET 4 the minimum requirement (might be an issue with Mono?). |