How would you avoid the InvalidOperationException created by the MSMQ sender and receiver below? Any help you can offer would be greatly appreciated!
I have a feeling it might be related to the BodyType attribute of the sender, but I do not know the proper domain of values for the attribute.
Sender code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Messaging;
namespace MSMQTester
{
class Program
{
static void Main(string[] args)
{
MessageQueue q = new MessageQueue(@"lab\test");
q.Formatter = new ActiveXMessageFormatter();
Message msg = new Message();
msg.Priority = MessagePriority.High;
msg.Body = "<hello_world />";
msg.Label = "test1";
q.Send(msg);
}
}
}
Receiver code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Messaging;
namespace MSMQViewer
{
class Program
{
static void Main(string[] args)
{
MessageQueue q = new MessageQueue(@"lab\test");
q.Formatter = new ActiveXMessageFormatter();
while (true)
{
Message msg = q.Receive();
Console.WriteLine(msg.Body);
}
}
}
}
Error message:
C:\dev\MSMQTester\MSMQViewer\bin\Debug>MSMQViewer.exe
Unhandled Exception: System.InvalidOperationException: Cannot deserialize the me ssage passed as an argument. Cannot recognize the serialization format. at System.Messaging.ActiveXMessageFormatter.Read(Message message) at System.Messaging.Message.get_Body() at MSMQViewer.Program.Main(String[] args) in c:\dev\MSMQTester\MSMQViewer\Pro gram.cs:line 18