No problem with creating queue and sending message. But I get a System.InvalidOperationException: There was an error reflecting type 'System.Messaging.Message' error at the mq.Receiver() statement.
It appears the mq.Receive() ran and got the messageReceivedLabel. The problem is with messageReceivedBody. I confirmed that the Body of the message sitting in the queue before the Receive() statement is in XML format (default).
What do I need to do the receive the Body of the message correctly?
From your code snippet, the body of the message you sent is a string object. The message body has been serialized into stream when the message is sent. So when receiving the message, we can actually deserialize the message body stream back to string object.
Based on above analyze, the MessageQueue.Formatter should be set to format the object whose type if string and not typeof Message. Therefore, I guess you code snippet can be modified as below to fulfill your target.
If you have any questions, please be free to let me know.
Best Regards, Lingzhi
Please remember to mark the replies as answers if they help and unmark them if they provide no help.