[CSHARP-1860] Decimal128 throws System.IO.EndOfStreamException Created: 03/Dec/16  Updated: 27/Oct/23  Resolved: 05/Dec/16

Status: Closed
Project: C# Driver
Component/s: BSON
Affects Version/s: 2.4
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Shawn Shaddock Assignee: Robert Stam
Resolution: Works as Designed Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

C# Driver 2.4.0
MongoDB 3.4.0


Issue Links:
Related
is related to SERVER-27317 Inserting a document with a Decimal12... Closed

 Description   

When attempting to serialize System.Decimal as BsonType.Decimal128

[BsonRepresentation(BsonType.Decimal128)]
public decimal Amount { get; set; }

An EndOfStreamException is thrown:
MongoDB.Driver.MongoConnectionException: An exception occurred while receiving a message from the server. ---> System.IO.EndOfStreamException: Attempted to read past the end of the stream.



 Comments   
Comment by Robert Stam [ 05/Dec/16 ]

I was able to reproduce this on my system. The exception is occurring (for me at least) because the server closed the connection. I see the following message in my server logs:

2016-12-05T10:09:44.369-0500 I -        [conn3] AssertionException handling request, closing client connection: 22 Client Error: bad object in message: Cannot use decimal BSON type when the featureCompatibilityVersion is 3.2. See http://dochub.mongodb.org/core/3.4-feature-compatibility.
2016-12-05T10:09:44.369-0500 I -        [conn3] end connection 127.0.0.1:62968 (4 connections now open)

The server comes up in 3.2 compatibility mode if it finds an existing database that was created with a 3.2 version of the server.

In my case I simply deleted my C:\data\db directory contents and ran the test again and it worked fine (the server comes up in 3.4 compatibility mode when data\db is empty).

Assuming you have existing data in \data\db that you don't want to delete see:

https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/#dbcmd.setFeatureCompatibilityVersion

for information about enabling new 3.4 features when running against existing databases.

Let me know if your situation doesn't match what I just described.

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