跪求高手解决System.NullReferenceException的异常

caoluainiefan 2009-03-18 09:32:38
我在客户端异步接收socket代码如下
TcpListener listener = new TcpListener(IPAddress.Parse(ipLocal), port);
listener.Start();
for (; ; )
{
string recv_msg = new StreamReader(listener.AcceptTcpClient().GetStream()).ReadLine();
AsyncEventHandler asy = new AsyncEventHandler(p.Send);
asy.BeginInvoke(recv_msg, new AsyncCallback(p.callBack), asy);
//asy.EndInvoke(ia);
}
Send()的方法为:lib.sendMessage(user_email, msg);
在sendMessage()方法体里这样添加消息队列:
public void sendMessage(string msn_email, string msg)
{msn_email = msn_email.ToLowerInvariant();
Contact contact = messenger.ContactList[msn_email];
Dictionary<DateTime, string> dic_msgs = new Dictionary<DateTime, string>(0);
if (_user_messages.ContainsKey(msn_email))
{
// 如果原来有此人的未发出消息,则增加
dic_msgs = _user_messages[msn_email];
dic_msgs.Add(DateTime.Now, msg);
_user_messages[msn_email] = dic_msgs;
}
else
{
// 如果没有此人的消息,则创建
dic_msgs.Add(DateTime.Now, msg);
if (dic_msgs != null)
{
_user_messages.Add(msn_email, dic_msgs);
}
}
我在本地测了很多回都不会出现那个异常,可一到服务器就会报错,跪求高手解决难题!
...全文
381 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
春天的气息 2009-03-18
  • 打赏
  • 举报
回复

TcpListener listener = new TcpListener(IPAddress.Parse(ipLocal), port);
listener.Start();
for (; ; )
{
string recv_msg = new StreamReader(listener.AcceptTcpClient().GetStream()).ReadLine();
AsyncEventHandler asy = new AsyncEventHandler(p.Send);
asy.BeginInvoke(recv_msg, new AsyncCallback(p.callBack), asy);
//asy.EndInvoke(ia);
}
Send()的方法为:lib.sendMessage(user_email, msg);
在sendMessage()方法体里这样添加消息队列:
public void sendMessage(string msn_email, string msg)
{msn_email = msn_email.ToLowerInvariant();
Contact contact = messenger.ContactList[msn_email];
Dictionary <DateTime, string> dic_msgs = new Dictionary <DateTime, string>(0);
if (_user_messages.ContainsKey(msn_email))
{
// 如果原来有此人的未发出消息,则增加
dic_msgs = _user_messages[msn_email];
dic_msgs.Add(DateTime.Now, msg);
_user_messages[msn_email] = dic_msgs;
}
else
{
// 如果没有此人的消息,则创建
dic_msgs.Add(DateTime.Now, msg);
if (dic_msgs != null)
{
_user_messages.Add(msn_email, dic_msgs);
}
}



错误提示是什么?停在哪行?

有没有可能是动态库的原因,你打包软件是否打全了dll或ocx文件。
oyljerry 2009-03-18
  • 打赏
  • 举报
回复
先定位异常的错误,是不是有空的引用操作等...
jlj84237485 2009-03-18
  • 打赏
  • 举报
回复
帮顶一下
wenblue7 2009-03-18
  • 打赏
  • 举报
回复
up
SAMINCsharp 2009-03-18
  • 打赏
  • 举报
回复
找出是那条语句抛出的异常,这种异常出现一般是没有实例化对象,看看是那个变量没有实例化的
  • 打赏
  • 举报
回复
具体哪行报错不知道?

110,546

社区成员

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

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

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