1

I have an application writing BsonDocuments created by MongoDB C# driver (v1.10.xxx) as byte array to RabbitMQ. Then I have another application which was using the same driver to read and convert the byte representation of the BsonDocument back to it's object form.

Then, I needed to upgrade the MongoDB C# driver to version 2.3, now I can't read back the bytes waiting in RabbitMQ queue back to BsonDocument, the structure remains but the values are gone.

Does anyone have an idea for that?

The code responsible for writing to RabbitMQ:

BinaryFormatter bf = new BinaryFormatter();
using (MemoryStream ms = new MemoryStream())
{
    bf.Serialize(ms, prm_xBsonDocument);
    lock (m_xChannelMessageTrace)
    {
        m_xChannelMessageTrace.QueueBind(m_strQueueNameMessageTrace, m_strExchangeNameCommunication, prm_TraceType.ToString(), null);
        m_xChannelMessageTrace.BasicPublish(m_strExchangeNameCommunication, prm_TraceType.ToString(), null, ms.ToArray());
    }
}

For reading I use:

var consumer = new EventingBasicConsumer((IModel)property);
consumer.Received += (model, ea) =>
{
    var ms = new MemoryStream(ea.Body);
 
    try
    {
        var formatter = new BinaryFormatter();
        BsonDocument xBsonDocument = ((BsonDocument)formatter.Deserialize(ms));

Writer app MongoDB C# driver version: v1.10.0.62

Reader app MongoDB C# driver version: v2.3.0.157

The RabbitMQ record starts like:

\0\0\0\0����\0\0\0\0\0\0\0\f\0\0\0QMongoDB.Bson, Version=1.10.0.62, Culture=neutral, PublicKeyToken=f686731cfb9cc103\0\0\0MongoDB.Bson.BsonDocument\0\0\0\t_elements\b_indexes_allowDuplicateNamesBsonValue+bsonType\0�System.Collections.Generic.List1[[MongoDB.Bson.BsonElement, MongoDB.Bson, Version=1.10.0.62, Culture=neutral, PublicKeyToken=f686731cfb9cc103]]�System.Collections.Generic.Dictionary2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]MongoDB.Bson.BsonType\0\0\0\0\0\0\t\0\0\0\t\0\0\0\0����MongoDB.Bson.BsonType\0\0\0\avalue_\0\b\0\0\0\0\0\0\0\0\0�System.Collections.Generic.List`1[[MongoDB.Bson.BsonElement, MongoDB.Bson, Version=1.10.0.62, Culture=neutral,...

Taha Paksu
  • 15,371
  • 2
  • 44
  • 78

0 Answers0