[2.0] "object reference not set to an object", driving me nuts..pls help
I get this error when I am creating myXmlNodeReader object. I am confused. i have already declared the variable and now I am creating an instance of XmlNodeReader object. why shouuld I get this error? thanks
I have declared this variable as public scope.
public XmlNodeReader myXmlNodeReader;
public XmlNodeReader LoadXmlDoc()
{
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.Load(@"c:\web.config");
ADgroups = new List<string>();
myXmlNodeReader = new XmlNodeReader(myXmlDocument.SelectSingleNode("configuration//appSettings"));
return myXmlNodeReader;
Re: [2.0] "object reference not set to an object", driving me nuts..pls help
maybe the node you want to select doesn't exist in the XML file you are reading, or it cannot be found (you need to validate the XML file to make sure)
Re: [2.0] "object reference not set to an object", driving me nuts..pls help
I am looking at the web.config file using xml spy. I can clearly see the appSettings element in that file.
Re: [2.0] "object reference not set to an object", driving me nuts..pls help
Please put your code in [code]code here[/code] tags so it is readable.
What line does the error occur on?
Re: [2.0] "object reference not set to an object", driving me nuts..pls help
Code:
[
public XmlNodeReader LoadXmlDoc()
{
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.Load(@"c:\web.config");
ADgroups = new List<string>();
myXmlNodeReader = new XmlNodeReader(myXmlDocument.SelectSingleNode("configuration//appSettings"));
return myXmlNodeReader;
}
Re: [2.0] "object reference not set to an object", driving me nuts..pls help
That doesn't help at all. Indent your code and, as I said, highlight the line upon which the error occurs. I'm not psychic.
Re: [2.0] "object reference not set to an object", driving me nuts..pls help
Code:
public XmlNodeReader LoadXmlDoc()
{
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.Load(@"c:\web.config");
ADgroups = new List<string>();
//The error happens in the next line. and the error is "Object reference not set to an object.
myXmlNodeReader = new xmlNodeReader (myXmlDocument.SelectSingleNode("configuration//appSettings"));
return myXmlNodeReader;
}
Re: [2.0] "object reference not set to an object", driving me nuts..pls help
SORRY ignore.
I don't how to post the code properly. I will figure out a way.
Re: [2.0] "object reference not set to an object", driving me nuts..pls help
If I remove the line
Code:
ADgroups = new List<string>();
the code works fine. Maybe I don't know, but couldn't figure out what is it for and doesn't seem to be relevant to the error as well. This is what I did
VB Code:
XmlDocument myXmlDocument = new XmlDocument();
myXmlDocument.Load(@"C:\test.xml");
myXmlNodeReader = new XmlNodeReader(myXmlDocument.SelectSingleNode("Configuration/Application/Name"));
myXmlNodeReader.Read();
Console.WriteLine (myXmlNodeReader.ReadInnerXml());
//return myXmlNodeReader;
and can see the output as expected.
Re: [2.0] "object reference not set to an object", driving me nuts..pls help
for some reason, I can't read any xml files on my box .
weird. any reason that could be ?
nath