Can't get keys from App.config file in Class Library project - am I missing something
Hi there,
I'm having a bit of trouble in a C# Class Library that I'm writing - when I try to get keys from the App.config file I'm getting nothing back. I copied the code from another project of mine (a Windows Service), which works fine there. Don't understand why nothing is being returned.
What I did was:
Added an Application Configuration File to my Class Library project, named the default App.config
It looks like this:
Used this code to try to read the key:
At the top of the class I'm using the System.Collections.Specialized for the NameValueCollection, the class compiles fine. I have a Windows Forms app just to test the class library, when I run the function that contains the code to read the key and step through, the CopyrightFolder remains as null (it's defined as string earlier in the code).
As I say - this code is the exact same as the other project - I'm a bit baffled as to why it's working in 1 and not the other?
Thanks
Hi there,
I'm having a bit of trouble in a C# Class Library that I'm writing - when I try to get keys from the App.config file I'm getting nothing back. I copied the code from another project of mine (a Windows Service), which works fine there. Don't understand why nothing is being returned.
What I did was:
Added an Application Configuration File to my Class Library project, named the default App.config
It looks like this:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key ="CopyrightFolder" value ="Copyright\\" />
<add key ="CopyrightTagWord" value ="CopyrightTag.docx" />
</appSettings>
</configuration>
Used this code to try to read the key:
Code:
NameValueCollection appSettings = ConfigurationManager.AppSettings;
CopyrightFolder = appSettings.Get("CopyrightFolder");
At the top of the class I'm using the System.Collections.Specialized for the NameValueCollection, the class compiles fine. I have a Windows Forms app just to test the class library, when I run the function that contains the code to read the key and step through, the CopyrightFolder remains as null (it's defined as string earlier in the code).
As I say - this code is the exact same as the other project - I'm a bit baffled as to why it's working in 1 and not the other?
Thanks
Last edited: