App.config question. Me is stuck good :-(

S

Simon

Hi everyone,

I really need help with the following:

It's common in app development to create numerous projects under one
solution that as a whole combine to become your final application. For
example I have a solution that has four subprojects - 3 class libraries and
1 windows forms app.

Q - Some of these projects - both class library and win form application
require access to a config file. In one of the projects - the one that
supports data access I use the line below to access a custom config section:

ChaosDataConfiguration config =
(ChaosDataConfiguration)ConfigurationSettings.GetConfig("TheChaosLibraries/DataProviderSettings");

The problem I'm having is I don't know if this is going to work. Should the
App.config file be placed under the data projects directory, or is there
some way to create a single config file at the root of the solution and have
all projects access that?

Any help would be greatfully received.

Thanks all
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

Create a file named app.config (yes, this is the exact name) under the
start-up project (the Winforms app in your case). When you run this project,
all the class libraries get copied to the project's 'bin' directory, as well
as the app.config file is renamed to "yourapp.exe.config" and also copied to
the 'bin' folder. Thus, you get a single config file!
 
M

Madhu[C#-MVP]

Hi,

Let me first get your problem correctly... You have a 4 projects, 1 which is
Windows Forms App and the other three class librarires. I assume it is going
to be DLL (basically in-process).

So in that case, you just have to have your application configuration in the
Windows Forms Application which will have the process of its own and all the
class libraries will be loaded into this process. The class libraries will
use the configuration file of the surrogate process which in this case is
the Windows forms App. You can just use the following code segment to access
the appsettings.

ConfigurationSettings.AppSettings[<appsettings-element>]

I guess this way you don't have to worry about multiple configuration files.

Hope this helps...

Regards,
Madhu

MCSD.NET | C# - MVP
 
S

Simon

Thats perfect guys. I'll give that a shot.

Thank you very much for your help

Kindest Regards

Simon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top