Click here to Skip to main content
15,867,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

My MSMQ listener code call the windows servce but when i start my window service it throws below message.

Am not sure where and what am missing,any help much appreciated

ERROR Msg from Event Log

Service cannot be started. System.InvalidOperationException: Cannot find a formatter capable of reading this message. at System.Messaging.Message.get_Body() at CRSMessagePipeline.CRSService.processMessage() at CRSMessagePipeline.CRSService.OnStart(String[] args) at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)
Posted

1 solution

The error message clearly states the problem. Your MSMQ queue reader has not implemented the correct formatter. It is very important for the code to know in which format will the queue object be read.

Below is the sample code, implement the same as per your data type:

C#
MessageQueue queue = new MessageQueue(@".\MyQueue");
System.Messaging.Message msg = new System.Messaging.Message();
msg = queue.Receive();
msg.Formatter = new System.Messaging.XmlMessageFormatter(new String[] { "System.String,mscorlib" });


Hope that helps.
 
Share this answer
 
Comments
shan1395 3-Jul-11 23:41pm    
Hi Amit,

Thanks for your help, here is my code
try
{
railMsg.Formatter = new XmlMessageFormatter(new Type[] { typeof(XmlElement) });
railMsg = externalQueue.Receive();
}
catch (Exception e)
{
logMessage("Error receiving message from queue: "+ e.Message);
}
Wild-Programmer 3-Jul-11 23:47pm    
Try putting the code "railMsg = externalQueue.Receive();" above "railMsg.Formatter = new XmlMessageFormatter(new Type[] { typeof(XmlElement) });".
meaning:
railMsg = externalQueue.Receive();
railMsg.Formatter = new XmlMessageFormatter(new Type[] { typeof(XmlElement) });
shan1395 4-Jul-11 0:05am    
Let me try and let you know the output
shan1395 4-Jul-11 1:03am    
Thanks Amit,that works like a charm
Wild-Programmer 4-Jul-11 3:55am    
I am glad it worked out for you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900