In most cases, the cause of message loss is one of the following scenarios:
awaitkeyword on async methods
async voidin the call stack
- Catching (generic) exceptions but not rethrowing the exception
All of these will prevent the recovery mechanism in NServiceBus from working correctly, as exceptions will not be caught by NServiceBus. This results in NServiceBus assuming processing was successful when it was not. Another side effect of the async-related issues is that transactions can be committed too early, which can cause corruption in storage.
Consider enabling message auditing so that the message is not lost.
Although all async methods that are provided in Particular APIs do not have the
Async suffix, these methods must be awaited. All async methods must be awaited, including async methods from other libraries.
Resolve this by:
- Adding the
awaitkeyword everywhere in the call stack.
- Most of the time, these issues are highlighted by the compiler as compiler warnings; consider enabling "warn as error".
- If await cannot be used, append
.. This is considered a workaround, and it's recommended to make the call stack fully asynchronous to prevent potential deadlocks
async void is very similar in behavior to missing await. This is often done to work around the fact that the method calls async methods, but the function invoking it does not have a valid signature.
async void MyAsyncVoidMethod();
async Task MyMethodAsync()
// async stuff
Resolve this by changing the signature to
async Task and
await the call in the method that is invoking this method. Also, see Missing await keyword above.
The following is often observed:
// Code that throws an exception is here
catch (Exception e)
The problem here is that the exception is caught and discarded. Therefore, NServiceBus will never receive this exception in its pipeline. From the NServiceBus perspective, everything is fine. The message will not be retried by the recovery mechanism.
Resolve this by:
- Completely removing the try-catch.
- Using the
throwkeyword in the
catch. Do not use
throw eas this hides some original exception details.
throw new Exception("My detailed reason for this exception with the original exception as inner exception", e).