class libraries - app.config

G

grs

Can a class library have a app.config file. Reason for asking is that the
microsoft application blocks all read from myApp.exe.config. How can you use
the application blocks if you do not have an app.config file.

Wish someone from microsoft would answer this, I am at a loss.

thanks
grs
 
N

Nicholas Paldino [.NET/C# MVP]

grs,

I'm not from MS, but I can tell you definitely that a library can not
have it's own application configuration section. The config file is to have
a single place to modify all aspects of the application. If you were able
to change these settings somewhere else, then you are basically going
against the wishes of the user of the client executable, and that generally
is a no no. You should create a custom configuration section in your
app.config file, and have your library read the settings from there (most
libraries in the framework do this already).

Hope this helps.
 
G

grs

thanks for reply Nicholas. My problem is that I am not in control of the
application that creates the config file but I am writing a library that
will be accessed by the program that is the "enterprise exe". It seems
totally wrong that we can not use the application blocks in a library
(unless we modify the source of the application blocks).

Any suggestions would be welcome.
grs


Nicholas Paldino said:
grs,

I'm not from MS, but I can tell you definitely that a library can not
have it's own application configuration section. The config file is to have
a single place to modify all aspects of the application. If you were able
to change these settings somewhere else, then you are basically going
against the wishes of the user of the client executable, and that generally
is a no no. You should create a custom configuration section in your
app.config file, and have your library read the settings from there (most
libraries in the framework do this already).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

grs said:
Can a class library have a app.config file. Reason for asking is that the
microsoft application blocks all read from myApp.exe.config. How can you
use
the application blocks if you do not have an app.config file.

Wish someone from microsoft would answer this, I am at a loss.

thanks
grs
 
R

Richard Grimes [MVP]

grs said:
thanks for reply Nicholas. My problem is that I am not in control of
the application that creates the config file but I am writing a
library that will be accessed by the program that is the "enterprise
exe". It seems totally wrong that we can not use the application
blocks in a library (unless we modify the source of the application
blocks).

As Nicholas says, a config file is associated with a process assembly not a
library. My FAQ on configuration addresses some of the issues:

http://www.grimes.demon.co.uk/dotnet/configFAQ.htm

For system objects the configuration will always be read from the app config
file, this is a *good* idea because it makes the settings global to the
application. However, if you simply want to provide settings for your own
classes, then you don't need to put those in the configuratiojn file at all.
Instead you can use a custom configuration scheme by defining your own
configuration object and deserialing it from disk when you want the settings
and serializing it to disk when you want to change a persisted setting.
There are several ways in .NET to do this, and I mention some of the options
in my FAQ.

Richard
 

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