joker77 Posted March 7, 2007 Posted March 7, 2007 (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 March 7, 2007 by joker77 Quote What if the Hokey-Pokey IS what it's all about?
Administrators PlausiblyDamp Posted March 7, 2007 Administrators Posted March 7, 2007 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
joker77 Posted March 8, 2007 Author Posted March 8, 2007 PlausiblyDamp - thanks again, forgot that DLLs don't use their own App.config! Quote What if the Hokey-Pokey IS what it's all about?
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.