MSMQ empty object on message body
- by Owen
Ok, so I'm very VERY new to MSMQ and I'm already confused.
I have created a private queue and added a few messages to it, all good so far. BUT when I retrieve the messages back from the queue the message body contains a empty object of the type I added. By this I don't mean that the body is null, it does have a reference to a type of the object that I added, but it's not instantiated so all the properties are in their null or default state.
This is the code I use to add to the queue:
using (var mQueue = new MessageQueue(QueueName))
{
var msg = new Message(observation)
{
Priority = MessagePriority.Normal,
UseJournalQueue = true,
AcknowledgeType = AcknowledgeTypes.FullReceive,
};
mQueue.Send(msg);
}
And this is the code that dequeues the messages:
using (var mQueue = new MessageQueue(QueueName))
{
mQueue.MessageReadPropertyFilter.SetAll();
((XmlMessageFormatter)mQueue.Formatter).TargetTypes =
new[] { typeof(Observation) };
var msg = mQueue.Receive(new TimeSpan(0, 0, 5));
var observation = (Observation)msg.Body;
return observation;
}