K
Kimmo Laine
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
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