[Mono-devel-list] Error when compiled code is run outside of monodevelop
John Bailo
jabailo at earthlink.net
Fri Sep 17 03:42:22 EDT 2004
When I run this code (see below) in monodevelop, it runs fine.
But when I run the .exe that monodevelop compiles at the line command it
produces the error:
jbailo at linux:~/MonoDevelopProjects/findnode/bin/Debug> ./findnode.exe
System.NullReferenceException: The value 'null' was found where an instance of
an object was required
at XMLSamps.readwrite.Main(String[])
Here is the code:
// project created on 9/16/2004 at 6:36 PM
using System;
using System.Xml;
using System.Xml.XPath;
namespace XMLSamps
{
public class readwrite {
static void Main(string[] args)
{
// Load your Xml document
XmlDocument mydoc = new XmlDocument();
mydoc.Load("./booklist2.xml");
int beg = 0;
XmlNode xmn = null;
//Use selectNodes to get the book node where the attribute
"id=1"
//and write out the response
//Console.WriteLine(DateTime.Now.Second*1000 +
DateTime.Now.Millisecond);
beg = DateTime.Now.Second*1000 + DateTime.Now.Millisecond;
try{
for(int i=0; i<1000000; i++)
{
// beg = DateTime.Now.Second*1000 +
DateTime.Now.Millisecond;
xmn = mydoc.SelectSingleNode("//book[@id='1']");
//Console.WriteLine(xmn.InnerHtml + " " + beg);
Console.WriteLine(xmn.InnerText + " elapsed " + ((DateTime.Now.Second*1000
+ DateTime.Now.Millisecond)-beg));
}
} catch(Exception e)
{ Console.WriteLine(e.ToString());
}
}
}
}
here is the way the data file, booklist2.xml looks:
<?xml version="1.0" encoding="utf-8" ?>
<booklist>
<book id="0">This is book0</book>
<book id="1">This is book1</book>
<book id="2">This is book2</book>
<book id="3">This is book3</book>
<book id="4">This is book4</book>
<book id="5">This is book5</book>
<book id="6">This is book6</book>
<book id="7">This is book7</book>
...
</booklist>
More information about the Mono-devel-list
mailing list