AK2005 - Error
ReceivePersistentActor.Command
message handler delegate must not be a void async delegate. Use ReceiveAsync
instead.
Cause
ReceivePersistentActor.Command
accepts an Action<TMessage>
as a delegate, any void async
delegate passed as an argument will be invoked as a detached asynchronous function that can cause erroneous message processing behavior.
An example:
using Akka.Actor;
using Akka.Persistence;
using System.Threading.Tasks;
public class MyActor: ReceivePersistentActor
{
public MyActor(string persistenceId)
{
PersistenceId = persistenceId;
Command<int>(async msg =>
{
await Task.Yield();
});
}
public override string PersistenceId { get; }
}
Resolution
using Akka.Actor;
using Akka.Persistence;
using System.Threading.Tasks;
public class MyActor: ReceivePersistentActor
{
public MyActor(string persistenceId)
{
PersistenceId = persistenceId;
// Use CommandAsync() if you're passing an asynchronous delegate
CommandAsync<int>(async msg =>
{
await Task.Yield();
});
}
public override string PersistenceId { get; }
}