Why this LINQ throws NullReferenceException?

57Richardb

New Member
\[code\]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(); }\[/code\]The xml config file:\[code\] <emailsetting> <stmp server="10.182.182.182" port="25" /> <from address="[email protected]"/> <to address=""/> <cc address=""/> </emailsetting>\[/code\]Why throws the exception:NullReferenceException was unhandledObject reference not set to an instance of an object.I'm new to LINQ,plz help.
 
Back
Top