[Last Call] Learn how to a build a cloud-first strategyRegister Now


.Net 4 - Using App.config from .dll

Posted on 2011-04-21
Medium Priority
Last Modified: 2012-05-11
I am using .NEt 4 and VS2010.
My application is a Windows forms App

In my solution I have 2 projects. A Windows Forms App and a Class Library (dll).

In my windows forms app I have an App.config file.

How do I access the settings in the App.config file from the classes that I have defined in my class library?
Question by:lachmann
  • 2
LVL 17

Expert Comment

by:Daniel Reynolds
ID: 35443478
You will need to create a class that or method in the dll that will accept as a variable the values in the config object or the config object in its entirety.

You can then refer to it within your dll.

Author Comment

ID: 35443501
I don't understand your comment. Example please?
LVL 10

Expert Comment

by:Asim Nazir
ID: 35443537

actually app.config placed in your UI project is used throughout the solution.
You can access values stored in this config, even in dll/library project.
In a nutshell, each application/exe has only one config file.

I hope it helps.
LVL 10

Accepted Solution

Asim Nazir earned 2000 total points
ID: 35443592
try adding a key, value to your app.config and then try to access this value in your dll/liib project using ConfigurationManager.appsettings["key"]
you may need to add reference to system.configuration assembly.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question