WPF – Using an Application Configuration File
Fri ,05/02/2010This is going to be a real short post about an issue that I ran into recently with WPF.
I was wanting to use an app config file with my WPF application. I was running into an issue with the ConfigurationManager calls not getting the information from the app config file.
I added the app config just like I would in a Windows Form..

My app config file looked something like this…
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="myKey" value="SomeValue" />
</appSettings>
</configuration>
I was using the standard code that works fine in Windows Forms(needed to add a reference to the System.Configuration):
using System.Configuration
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var myKey = ConfigurationManager.AppSettings["myKey"];
}
However, the app settings were not being found. After scratching my head for a while and searching numerous places online, I found a small response on a forum. None of the “MVP”s picked up on it. It was because of the name of the app config file. By default, VS2008 added the file as “App1.config”. For some reason, the ConfigurationManager class looks for a file named exactly “App.config”.
So simply changing the name of the config file to “App.config” fixed the issue and the code started working.
