Invalid cast exception on MQ

Hi, we have a strange one; after a week or so in the wild, we start getting reports of an MQ-based feature “Stopping working”. I then look in Redis, and in the key space:


there are lots of Invalid Cast Exceptions - namely:

"message": "Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' to type 'SendEmailRequest'.",

A restart of the app pool stops this happening until the next time it happens a few days later. Any ideas?

Are you trying to call any Services via MQ that return a generic Dictionary<,>? They should return Response DTOs.

No, BUT, could this be caused by the MQ service returning HttpResult without a response rather than the type defined in IReturn?

HttpResult doesn’t implement/inherit Dictionary but the MQ message handlers does expect a response DTO not a HttpResult. I’ve changed it to unwrap it in this commit to see if it resolves it.

Will let you know after it passes CI and is published on MyGet.

This change is now available from v5.7.1 that’s now available on MyGet.

Sir, you are a legend. In meantime I will update our system to remove httpresults from any MQ services

1 Like