Jump to content
Xtreme .Net Talk

Can't get keys from App.config file - am I missing something?


Recommended Posts

Posted (edited)

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:

<?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:

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

Edited by joker77
What if the Hokey-Pokey IS what it's all about?
  • Administrators
Posted

Re: Can't get keys from App.config file in Class Library project - am I missing somet

 

Where is the config file located and what is it's filename? Dlls don't have their own config files - they load their settings from the calling executable's config file.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...