By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

MSMQ and the Message.Body property

P: n/a
Hi,

how can i be sure that the MSMQ Message.Body property contains something
valid? If i send the message like this:

public void SendMyMessage( int msgCode, object msgData ) {
Message msg = new Message();
msg.AppSpecific = msgCode;
msg.Body = msgData;

m_MyQueue.Send( msg );
}

Sometimes the msgData is valid object (array of objects actually) and
sometimes its just null. When its null and i try to check it

if( msg.Body != null ) {
// . . .
}

I get XmlException - "The root element is missing"! If i but empty string
into Body-field when i donīt have data: XmlException again, with the same
message.

The Message.BodyType seems to be allways 0. MessageQueue formatter is set
like this:

myQueue.Formatter = new XmlMessageFormatter( new Type[] { typeof(
object[] ) } );
I could do it like this

object[] data;
try {
data = ( object[] )msg.Body;
} catch ( Exception exc ) {
data = null;
}

but i donīt like this... Is there a better way? Am i missing something?
thx

Kimmo Laine
Nov 16 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.