v4 and MongoDB saga/statemachine persistence

48 views
Skip to first unread message

Nick Archibald

unread,
Feb 20, 2018, 1:54:33 PM2/20/18
to masstransit-discuss
Hi Guys

I am trying to get a Saga/statemachine working with MongoDB Persistence. I currently have it working where the initail event is persisted but I get the following exception when receiving other messages that should match to the initial one.

System.FormatException: Element '_id' does not match any field or property of class CmeConnect.LimeSurvey.Common.Sagas.States.HookBatchState.

   at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.DeserializeClass(BsonDeserializationContext context)

   at MongoDB.Bson.Serialization.BsonClassMapSerializer`1.Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)

   at MongoDB.Bson.Serialization.IBsonSerializerExtensions.Deserialize[TValue](IBsonSerializer`1 serializer, BsonDeserializationContext context)

   at MongoDB.Driver.Core.Operations.CursorBatchDeserializationHelper.DeserializeBatch[TDocument](RawBsonArray batch, IBsonSerializer`1 documentSerializer, MessageEncoderSettings messageEncoderSettings)

   at MongoDB.Driver.Core.Operations.FindCommandOperation`1.CreateCursorBatch(BsonDocument commandResult)

   at MongoDB.Driver.Core.Operations.FindCommandOperation`1.CreateCursor(IChannelSourceHandle channelSource, BsonDocument commandResult, Boolean slaveOk)

   at MongoDB.Driver.Core.Operations.FindCommandOperation`1.<ExecuteAsync>d__111.MoveNext()

--- End of stack trace from previous location where exception was thrown ---

   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)


I think it might be with my correlation setup but it looks correct when comparing with the ShoppingCart example. Does the exception ring anyone's bell?

Is there a example anyone can link me that using MongoDB persistence for a sag?

Thanks

Nick

Nick Archibald

unread,
Feb 21, 2018, 5:56:15 AM2/21/18
to masstransit-discuss
OK I worked this one out.

The exception is occurring because it can't serialize the '_id'  field into the class object I have. However the '_id' value should have been the CorrelationId. So to help the serializer out I added the [BsonElement("_id")] to the CorrelationId property. This tells the serialize to map the CorrelationId to the MongoDB's _id field. So what you see in MongoDB is no CorrelationId property on the document but the _id field is containing this value.

Maybe this might help someone or someone can tell me whether there is a better way.

Chris Patterson

unread,
Feb 21, 2018, 5:34:43 PM2/21/18
to masstrans...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-discuss+unsub...@googlegroups.com.
To post to this group, send email to masstransit-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/bd9ee9f0-4f3c-409e-a8a4-0205c817ae7a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages