Using the MongoDB persistance engine in joliver/EventStore causing the error Unknown discriminator value 'MyEvent'
. The issue is only caused when I try to load all events for replaying the events like this.storeEvent.Advanced.GetFrom(new DateTime(2010, 1,1))
The issues is caused in ExtensionsMethods.cs
public class MyClassEvent : IDomainEvent { ... }
public static Commit ToCommit(this BsonDocument doc, IDocumentSerializer serializer)
{
if (doc == null)
return null;
var id = doc["_id"].AsBsonDocument;
var streamId = id["StreamId"].AsGuid;
var commitSequence = id["CommitSequence"].AsInt32;
var events = doc["Events"].AsBsonArray.Select(e => e.AsBsonDocument["Payload"].IsBsonDocument ? BsonSerializer.Deserialize<EventMessage>(e.AsBsonDocument["Payload"].AsBsonDocument) : serializer.Deserialize<EventMessage>(e.AsBsonDocument["Payload"].AsByteArray)).ToList();
var streamRevision = doc["Events"].AsBsonArray.Last().AsBsonDocument["StreamRevision"].AsInt32;
return new Commit(
streamId,
streamRevision,
doc["CommitId"].AsGuid,
commitSequence,
doc["CommitStamp"].AsDateTime,
BsonSerializer.Deserialize<Dictionary<string, object>>(doc["Headers"].AsBsonDocument),
events);
}
My configuration is like this:
Wireup.Init()
.UsingMongoPersistence(connectionName, new DocumentObjectSerializer())
.UsingBsonSerialization()
.UsingAsynchronousDispatcher()
.PublishTo(this.container.Resolve<IPublishMessages>())
.Build();
But have tried almost all kind of serializer options.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…