Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3630460
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:16:22+00:00 2026-05-19T00:16:22+00:00

I have the following projects: MVC Console application Class library Windows forms application COM

  • 0

I have the following projects:

  1. MVC
  2. Console application
  3. Class library
  4. Windows forms application
  5. COM Library

All these applications need to use a single configuration file. As far as I understand, app.config files are for windows, console applications and class libraries when web.config are for the web projects.

The same configuration need to be accessible in all of these projects. I have read that it’s suggested to use machine configuration file, but we won’t always have access to that, therefore configuration files must reside within our solution.

I don’t fully understand how the configuration files get build. Currently I wrote a simple project where I have the following:

  1. Class library to store for serving configuration files. A have attempted to do this through reflection.
  2. Windows application that should read the app.config from a class library.

When I execute the following code I expect to get a configuration file with test values:

_applicationSettings = ConfigurationManager.OpenExeConfiguration(
                    System.Reflection.Assembly.GetAssembly(typeof(WCSConfiguration)).Location
                    ).AppSettings;    

What I get instead is an empty application settings file.

Class library has the following App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="TestTextKey" value="TestTextValue"/>
  </appSettings> 
</configuration>

I have tried using .GetExecutingAssembly() method which I expect to return an assembly of a code that’s currently being executed. This didn’t work, instead it has returned the assembly of a Windows application.

GetAssembly(type(WCSConfiguration)) has returned a right assembly, however, the configuration file was missing in the bin/debug directory.

I have a feeling that either I’m doing something fundamentally wrong or Microsoft hasn’t made this flexible enough. I have also tried to search MSDN for explanation, but this hasn’t been documented well IMO.

I have also left COM in bold because I’m not sure whether any config files would be available to COM library at all. Firstly I would like to get other projects to work.

I understand that this is a lot of information. Any help would be greately appreciated. Previously we have chosen to use registry, but this has turned out to be nasty, mainly because access to registry is not available in some scenarios. Additionally we now have multiple versions of the applications and switching between branches is a half an hour job 🙁

Thank you

Edit:

If I add the dll’s config sections to app.config that means that these settings will be available only from that application. Please correct me if I’m wrong. Example that I have provided is a scaled down version. In total there are about ten windows applications, a single MVC project and range of class libraries all of which need to make a use of that configuration.

Configuration settings are mostly connection strings, lookup values that do not belong in the database and few other minor settings. Main concern at this point are the connection strings. There are few minor releases of the application where each release points to a different database.

What I’d like to get out of this is a good workable solution so that it can be posted online and other people who come across the same problem won’t spend days of their time.

Morale of the story IMO:
Use both App.config and Web.config to store location of your own configuration file.

Write simple XML serializer to read/write config and DLL for serving the configuration.

COM objects are a long story and were implemented with a “hack”, since neither App.config or Web.config are available in COM DLLs.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:16:22+00:00Added an answer on May 19, 2026 at 12:16 am

    Note ConfigurationManager.OpenExeConfiguration needs to be passed the filename of the config file, not the executable.

    You’ll need to append .config to the path of the executable. To get the exe assembly use Assembly.GetEntryAssembly.

    If you have configuration settings you want to share across multiple pieces of code that are not all in the same .NET Process, I would suggest:

    • Put them in their own myStuff.config.
    • In .NET code use ConfigurationManager.OpenExeConfiguration to open and access myStuff.config.
    • Non-.NET code will need to use an XML parser to load and read the settings. Unless you configuration structures are very complex this shouldn’t be too hard to encapsulate.
    • Put the path to myStuff.config in the app.config of each application sharing this configuration for .NET applications. (Not non-.NET applications: depends on what works for that application.)

    Another approach, where the configuration structure is the same but the settings are per-application would be a custom configuration section.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a S#arp MVC application with following projects/layers : Core (Model) Data Web
I have the following two projects in in Flex Builder 3: One AS3 library
I have the following package on Eclipse: com.mortgageapp.projects.app I'm not interested about the package
I have an ASP.NET MVC 3 application with 2 areas which are seperate projects
I have used LINQ-to-SQL in WPF and ASP.NET MVC projects in the following way:
I have three projects in my solution: Domain layer GUI MVC application Now my
In an MVC project I have the following classes: public abstract class Browse<T> where
I have created the following project structure for my new asp.net mvc project any
I have the following layout for my mvc project: /Controllers /Demo /Demo/DemoArea1Controller /Demo/DemoArea2Controller etc...
I have seen lot projects following this kind of coding style Any significant advantage

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.