.Net 4 - Using App.config from .dll

Posted on 2011-04-21
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
    LVL 17

    Expert Comment

    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

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

    Expert Comment

    by:Asim Nazir

    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

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now