Results 1 to 10 of 10

Thread: [2.0] "object reference not set to an object", driving me nuts..pls help

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    [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;

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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)
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    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.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    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;
    
    }

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    Unhappy 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;
    
    }

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    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.

  9. #9
    Fanatic Member
    Join Date
    Jun 2004
    Location
    All useless places
    Posts
    917

    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:
    1. XmlDocument myXmlDocument = new XmlDocument();
    2.     myXmlDocument.Load(@"C:\test.xml");
    3.  
    4.     myXmlNodeReader = new XmlNodeReader(myXmlDocument.SelectSingleNode("Configuration/Application/Name"));
    5.     myXmlNodeReader.Read();
    6.     Console.WriteLine (myXmlNodeReader.ReadInnerXml());
    7.     //return myXmlNodeReader;
    and can see the output as expected.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width