I'm afraid that your code works fine. It must be that the "temp" variable is string.Empty or whitespace.
I created an XmlDocument (from XDocument, sorry. I think it's a lot easier to work with) that looks like what you're targeting and ran your code. It runs fine and gives a proper value:
var xDoc = new XDocument(
new XDeclaration("1.0", "UTF-8", "no"),
new XElement("root",
new XElement("account",
new XElement("systemInfo",
new XElement("dskInfo",
new XElement("dskInterface",
new XElement("size", 53999759360)))))));
var doc = new XmlDocument();
using (var xmlReader = xDoc.CreateReader())
{
doc.Load(xmlReader);
}
XmlNodeList accountList = doc.GetElementsByTagName("account");
foreach (XmlNode node in accountList)
{
XmlElement accountElement = (XmlElement)node;
foreach (XmlElement dskInterface in node.SelectNodes("systemInfo/dskInfo/dskInterface"))
{
String temp = (dskInterface["size"].InnerText).ToString();
long iasdas = Convert.ToInt64(temp) / 1024; // Error Happens here
}
}
Edit: Here's an easier way to test what's actually happening:
Convert.ToInt64(null); // Doesn't crash
Convert.ToInt64(string.Empty); // Crashes
Convert.ToInt64(""); // Will crash if you comment the line above
Convert.ToInt64(" "); // Will crash if you comment the lines above