I am experimenting with a new NServiceBus project using Azure Storage Queues for message transport and JSON serialization. I have noticed that when I run a message through the queue that is missing NServiceBus headers, for example an empty JSON message: { } It will throw the following warning message:
2020-02-06 17:46:35.587 WARN NServiceBus.Transport.AzureStorageQueues.MessagePump Azure Storage Queue transport failed pushing a message through pipeline
System.ArgumentNullException: Value cannot be null.
Parameter name: nativeMessageId
at NServiceBus.Transport.IncomingMessage..ctor(String nativeMessageId, Dictionary`2 headers, Byte[] body)
at NServiceBus.Transport.ErrorContext..ctor(Exception exception, Dictionary`2 headers, String transportMessageId, Byte[] body, TransportTransaction transportTransaction, Int32 immediateProcessingFailures)
at NServiceBus.Transport.AzureStorageQueues.ReceiveStrategy.CreateErrorContext(MessageRetrieved retrieved, MessageWrapper message, Exception ex, Byte[] body)
at NServiceBus.Transport.AzureStorageQueues.AtLeastOnceReceiveStrategy.<Receive>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NServiceBus.Transport.AzureStorageQueues.MessagePump.<InnerReceive>d__7.MoveNext()
After which point it appears to stop processing the message but leaves it in the queue. Then, after waiting the configured message invisible period, the message becomes visible in the queue again, and NServiceBus will repeat the 'warning and stop processing' process indefinitely. Is there any way to alter the way NServiceBus handles this scenario so that it will throw the message to the configured error queue when it is unable to parse header information and not attempt to process the message indefinitely?