关于消息队列,出现异常System.NullReferenceException: 未将对象引用设置到对象的实例

kobevivo 2010-04-16 02:47:25
关于消息队列,出现异常System.NullReferenceException: 未将对象引用设置到对象的实例

/// <summary>
/// 接受网络连接消息队列 并且更改xml
/// </summary>
public void StartReciveMessage()
{
try
{
MessageQueue MqReceive = MqServerOper.GetServerMqReciver();

MqReceive.Formatter = new System.Messaging.BinaryMessageFormatter();
while (true)
{
lock (locker)
{
//接受消息
System.Messaging.Message msg = MqReceive.Receive();
//消息描述信息
string strTitle = msg.Label.ToString();
//消息内容
string strBody = msg.Body.ToString();

XmlNodeList list = doc.SelectSingleNode("main").SelectSingleNode("rooms").ChildNodes;

foreach (XmlNode node in list)
{
if (node.Attributes["IP"].InnerText == strBody)
{
//更改网络状态为1 1是连接,0是断网
node.Attributes["OnlineState"].InnerText = "1";
//更改读取时间
node.Attributes["LastTime"].InnerText = DateTime.Now.ToString();
//保存文件
doc.Save("XML/RoomOnlineState.xml");
//进程停止0.1秒
System.Threading.Thread.Sleep(100);
break;

}
}
}
}
}
catch(Exception ex)
{
Log.Writelog("接受网络连接消息队列出现异常:"+ex.ToString());
}
}

跟踪是在这句:MqReceive.Formatter = new System.Messaging.BinaryMessageFormatter();
出现异常:System.NullReferenceException: 未将对象引用设置到对象的实例。

但是我换台机子测试此代码就不出现了,我这怎么回事,怎么解决?
...全文
134 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
z050301402 2010-04-16
  • 打赏
  • 举报
回复
空的没数据
Peter200694013 2010-04-16
  • 打赏
  • 举报
回复
换台机子测试此代码就不出现了?

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧