I've added the code in the answer to this question: Unknown discriminator value 'MyEvent', but it didn't help.
An error occurred while deserializing the Body property of class EventStore.EventMessage: Unknown discriminator value : "Insert event name". Error only occurs when you try to rehydrate a saved object after program restart.
Running latest MyGet Build
Sample Repository:https://github.com/tonyeung/EventStore-MongoDB
To replicate the issue:
run the program
press c to create a new record
press q to quit
run the program again
but press r to rehydrate
error triggers  
If you run the program, press c, press enter to continue, and press r to rehydrate without quitting, the object is rehydrated without a problem. WAT?
        using (var eventStore = WireupEventStore())
        {
            var snapshot = eventStore.Advanced.GetSnapshot(ID, int.MaxValue);
            if (snapshot == null)
            {
                // ERRORS HERE
                using (var stream = eventStore.OpenStream(ID, 0, int.MaxValue))
                {
                    var events = from s in stream.CommittedEvents
                                 select s.Body as IEvent;
                    obj.LoadsFromHistory(events);
                }
            }
        }
github issue: https://github.com/NEventStore/NEventStore/issues/203
I figured it out, since I was using an interface as a marker for my events, I had to change the query from the SO question from
        var types = Assembly.GetAssembly(typeof(SimpleCQRS.Event))
                .GetTypes()
                .Where(type => type.IsSubclassOf(typeof(SimpleCQRS.Event)));
to
        var type = typeof(IEvent);
        var types = Assembly.GetAssembly(typeof(IEvent))
                .GetTypes()
                .Where(t => type.IsAssignableFrom(t))
                .Where(t => t.IsClass);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With