How does NEventStore throws assert commits are uniquely identified?

157 views Asked by At

When I try to save the events to the store I get the following exception:

The commit must be uniquely identified.\r\nParameter name: attempt

But my code always generates a new New Guid for the commit (as per NEventStore example)

public void Save(Guid aggregateId, IEnumerable<Event> events, int expectedVersion)
{
    var eventList = events as IList<Event> ?? events.ToList();

    using (var scope = new TransactionScope())
    using (var stream = store.OpenStream(aggregateId, 0, int.MaxValue))
    {
        if(stream.StreamRevision != expectedVersion)
            throw new ConcurrencyException();

        foreach (var @event in eventList)
        {
            stream.Add(new EventMessage { Body = @event });
        }

        stream.CommitChanges(Guid.NewGuid());

        scope.Complete();
    }

    foreach (var @event in eventList)
    {
        publisher.Publish(@event);
    }
}

Does anyone have any idea why this is happening?

1

There are 1 answers

0
Saulo Vallory On BEST ANSWER

The message is misleading. It is thrown here when this check...

attempt.StreamId != Guid.Empty && attempt.CommitId != Guid.Empty

Is false. So it should say: both the CommitId and StreamId must not be empty.