Deserializing incomingMessage in CustomRetryPolicy method

I have this requirement: “send an email to the user if the message fails to process successfully”
So it though to use CustomRetryPolicy would be the best approach to make sure I send only One email of final faliure. But the emailaddress of the user and some other data I need are in the original message. The “ErrorContext” has Message.Body as a byte array. Question is:

How do I Deserialize the message body into the original Message object. How do I get a hold of the correct deserializer (Xml in this case) ?

The direct answer (how do you deserialize the message) I have is that you don’t - you shouldn’t.

The longer answer is it sounds like you are mixing infrastructure concerns (message failure notifications) and business concerns (the body of the message). Is it only this one message type that needs a notification on failure? Or is it all message types?

What’s driving the need for the notification in the first place? Generally you trust that messages will always be delivered and successfully processed eventually, otherwise (if they were invalid) they’d never get sent in the first place. So what would cause this particular failure? Maybe this is a case where the failure condition is actually a business case, and the message should be processed successfully and generate a new message, whose handler would send an email.

So, it would be good to dive a little deeper into the requirements you’ve been given.