I want to transfer messages using MSMQ. When I'm sending a message, I pass an enum (StudentMessageType) as AppSpecific so I can recognize what should I do in the destination. But when I try to receive the message, I can't access AppSpecific property and I get this exception:
Property AppSpecific was not retrieved when receiving the message. Ensure that the PropertyFilter is set correctly.
What should I do to receive AppSpecific?
Send
var requestQueue = new MessageQueue(@".\private$\req");
requestQueue.MessageReadPropertyFilter.AppSpecific = true;
requestQueue.Formatter = new BinaryMessageFormatter();
Message studentNameMessage = new Message(studentName, new BinaryMessageFormatter());
studentNameMessage.AppSpecific = (int) Student.StudentMessageType.AddStudent;
requestQueue.Send(studentNameMessage, MessageQueueTransactionType.Single);
requestQueue.Close();
Receive
requestQueue = new MessageQueue(@".\private$\req");
requestQueue.Formatter = new BinaryMessageFormatter();
MessageQueueTransaction transaction = new MessageQueueTransaction();
try
{
transaction.Begin();
Message message = requestQueue.Receive(transaction);
output = (string)message.Body;
output += "\t" + ((Student.StudentMessageType) message.AppSpecific).ToString();
transaction.Commit();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}