【发布时间】:2012-07-16 09:49:55
【问题描述】:
private SmtpClient getServer()
{
return (from e in doc.Elements("emailsetting")
select new SmtpClient()
{
Host = e.Attribute("server").Value,
Port = Convert.ToInt32(e.Attribute("port").Value)
}).FirstOrDefault();
}
xml配置文件:
<emailsetting>
<stmp server="10.182.182.182" port="25" />
<from address="ithelpdest@citics.com.hk"/>
<to address=""/>
<cc address=""/>
</emailsetting>
为什么会抛出异常: NullReferenceException 未处理 对象引用未设置为对象的实例。
我是 LINQ 新手,请帮助。
【问题讨论】:
-
'smtp' 在 XML 中拼写为 'stmp'。 :)