Thread: reading from xml

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    44

    reading from xml

    Code:
    using System.Configuration;
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                String counter = ConfigurationManager.AppSettings["counter"].ToString();
                Console.WriteLine(counter);
            }
        }
    }
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    	<appSettings>
    		<add key="counter" value="15"/>
    	</appSettings>
    </configuration>
    Unhandled Exception: System.NullReferenceException: Object reference not set to
    an instance of an object.

    I am a bit tired so I quess there is some stupid mistake I am making here but can you help???

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You're trying to access a member/method on a null pointer, most likely AppSettings["counter"] returns null. Check this.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-02-2009, 07:27 AM
  2. Reading XML returned from a POST
    By ltcabral in forum C Programming
    Replies: 2
    Last Post: 04-07-2008, 10:28 AM
  3. reading xml
    By Yarin in forum C++ Programming
    Replies: 3
    Last Post: 10-08-2007, 01:36 AM
  4. Reading XML
    By mdoland in forum C# Programming
    Replies: 7
    Last Post: 09-14-2007, 02:18 AM
  5. reading and writing xml using c
    By cnu_sree in forum C Programming
    Replies: 3
    Last Post: 04-20-2007, 05:25 AM