[CSHARP-1255] An ignored BsonElement with a prefix of a known BsonElement's causes an EndOfStreamException Created: 26/Apr/15  Updated: 02/Apr/16  Resolved: 01/May/15

Status: Closed
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.0
Fix Version/s: 2.0.1, 2.1

Type: Bug Priority: Critical - P2
Reporter: Peter Gordon Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB C# Legacy Driver version 2.0


Attachments: Zip Archive TestApp.zip    
Issue Links:
Duplicate
is duplicated by CSHARP-1280 Deserializing fails if a document con... Closed
is duplicated by CSHARP-1261 Using _ts as element name for types p... Closed

 Description   

This occurs when a class map is being deserialized which includes a non-mapped element which is the prefix of a mapped element. For example, given the class map:

[BsonIgnoreExtraElements]
public class Test
{
	public int Longer { get; set; }
}

Attempting to deserialize the document:

{ Long: 20 }

will result in an EndOfStreamException.



 Comments   
Comment by Githook User [ 01/May/15 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1255: fixed issue with prefixed mapped fields interferring with other unmapped and ignored fields.
Branch: v2.0.x
https://github.com/mongodb/mongo-csharp-driver/commit/f4b7fb1a7e5755834d270a4f802c3d71cee0b120

Comment by Githook User [ 01/May/15 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1255: fixed issue with prefixed mapped fields interferring with other unmapped and ignored fields.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/c5d064fb1f62eaef14623a0e7e8261fe2de8d35e

Comment by Peter Gordon [ 27/Apr/15 ]

Craig,

Thanks ... I can work around the problem on the short term ... I only have a small set of instances in my app where this has an impact. I likely won't be rolling out a change to our production environment until after 2.0.1 is released anyway.

Peter

Comment by Craig Wilson [ 27/Apr/15 ]

Peter,

Thanks for the reproduction. I narrowed it down to the problem. I've updated the description of the ticket to be more concise about the exact issue. I couldn't think of a good workaround for this other than to (a) map the fields or (b) use a different name. I know this is an existing application, so neither of these may be valid. We'll be working on a 2.0.1 release shortly and this fix will be included.

Thanks so much for the bug report and your patience,
Craig

Comment by Craig Wilson [ 27/Apr/15 ]

Thanks Peter, I'll let you know what I find.

Craig

Comment by Peter Gordon [ 27/Apr/15 ]

Test console app to reproduce error

Comment by Peter Gordon [ 27/Apr/15 ]

Hi Craig,

It's very strange - I could have sworn that the test code I sent yesterday generated the error. Tried again this morning in my project and sure enough ... no error.

That said - I created a very quick and small standalone console app that reproduces the error I am having. While I thought it was related to have an array of objects not identified in the model, it seems that the issue is a little more complex than that. The model we are having an issue with in our production system is quite complex so I simplified it as much as I could wile still having the error occur.

I'm attaching a zip file of the project files ... let me know if you need anything else.

Thanks for looking into this.

Peter

Comment by Peter Gordon [ 27/Apr/15 ]

I'll try to get you a small app later today or tomorrow.

Thanks

Comment by Craig Wilson [ 27/Apr/15 ]

Hi Peter,

I can't reproduce this. I'm working off of master. If you could either submit a test or a fully functioning console app that breaks, it would be truly appreciated. You can see my attempts here: https://github.com/craiggwilson/mongo-csharp-driver/commit/06cf9ae801d464144d6dedf9349b55670425cee4.

Craig

Comment by Craig Wilson [ 26/Apr/15 ]

Peter,

Thanks for the reproduction code above. I'll take a look tomorrow.

Craig

Generated at Wed Feb 07 21:39:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.