Raggaer
Raggaer

Reputation: 3318

C# ConfigurationManager not returning value

I'm trying to get a value from my configuration file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="MusicPath" value="C:/Users/Alvaro/Music" />
  </appSettings>
</configuration>

And this is how I handle it

this.config = new ConfigurationHandler();
String musicPath = this.config.MusicPath();
DirectoryInfo dinfo = new DirectoryInfo(musicPath);

And this is the ConfigurationHandler class

namespace RaggaerPlayer.Class
{
    class ConfigurationHandler
    {
        public String MusicPath()
        {
            String path = ConfigurationManager.AppSettings["MusicPath"];

            return path;
        }
    }
}

But I got an error at the DirectoryInfo variable "Value cannot be null".. what am I doing wrong?

Upvotes: 0

Views: 638

Answers (1)

Carlos Rodriguez
Carlos Rodriguez

Reputation: 2220

I believe the file should be named App.config. You could rename it, but I think this causes versioning problems.

Upvotes: 1

Related Questions