Hi there,

I’m using the .NET API to write a set of events to Event Store using the AppendToStreamAsync method.

I’ve noticed the following error in my logs:

“EventStore.ClientAPI.Exceptions.CommandNotExpectedException: Expected : WriteEventsCompleted. Actual : WriteEvents.”

I’m not quite sure how to interpret this error because I’m not opening a transaction. I couldn’t find anything useful from a bit of googling and so was hoping someone would be able to enlighten me.

Thanks in advance,


Can you post the code that’s writing? Are you using the client connected to a server, or the embedded client?

Thanks for the quick reply.

This the function that actually adds the events to event store:


   public Task Add(Message message)
            _logger.DebugFormat("Adding message to Event Store Message Store: {0}", JsonConvert.SerializeObject(message));
            var eventBody = Encoding.UTF8.GetBytes(message.Body.Value);

            var headerBagJson = JsonConvert.SerializeObject(message.Header, new KeyValuePairConverter());
            var eventHeader = Encoding.UTF8.GetBytes(headerBagJson);

            var eventData = new[] { new EventData(message.Id, message.Header.Topic, true, eventBody, eventHeader) };

            var numberOfPreviousEvent = GetEventNumber(message.Header) - 1;
            return _eventStore.AppendToStreamAsync(GetStreamId(message.Header), numberOfPreviousEvent, eventData);


This function is called in this context:



This is called once per message that I want to store.

I know this is not ideal in terms of not batching the events and calling wait, but the above are part of a library we’re using and so the application code does not have direct access to the Event Store API.

We’re using a client connected to a server. Anything else that would be useful to know?


There’s nothing obviously wrong with that code from first sight, but calling .Wait() has all kinds of bizaare side effects depending what thread it is running on etc. Are you able to reproduce this with your server using a simple Console app?

This sounds like a self connected TCP socket. How are you connecting
to event store?

Not currently able to repo it at the minute unfortunately and I’m using the .NET TCP client.

Are you using ephemeral ports? :slight_smile:

This is exactly what we ran into (you are receiving a command that
should be sent the other direction)

Ah that indeed may be the problem. Thanks for your help :slight_smile: