I recently updated from the MongoDB Driver from 2.7.2 to 2.10.4. After updating some of my larger queries throws this exception ‘The size of the message is invalid’. After digging through the Net driver source I found that more validation was added around July 1 2019 (CSHARP-1501: Drivers must raise an error if response messageLength > …). I’ve been trying to figure out how to set the MaxMessageSize. I found some information that makes me think its coming from the server (Azure CosmosDB). Is it possible to change this value?
I’ve checked the size of some data coming back from the older version and it’s only ~19 megs.
Here’s the method that throws the exception:
src/MongoDB.Driver.Core/Core/Connections/BinaryConnection.cs
private void EnsureMessageSizeIsValid(int messageSize)
{
var maxMessageSize = _description?.MaxMessageSize ?? 48000000;
if (messageSize < 0 || messageSize > maxMessageSize)
{
throw new FormatException("The size of the message is invalid.");
}
}
I’ve followed the _description.MaxMessageSize back to the src/MongoDB.Driver.Core/Core/Connections/IsMasterResult.cs
public int MaxMessageSize
{
get
{
BsonValue value;
if (_wrapped.TryGetValue("maxMessageSizeBytes", out value))
{
return value.ToInt32();
}
return Math.Max(MaxDocumentSize + 1024, 16000000);
}
}
Any help would be greatly appreciated.