By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

ClassLibrary.DLL and app.config files

P: n/a

Hi,

We have a class library application that needs to read some application
settings from it's own app.config file.

I assume that a ClassLibrary.DLL can have a app.config file, but during
runtime, it run within the context of another main application that has its
own app.config file (am I correct?)

My main question is how can I control a ClassLibrary.DLL to read its own
app.config or the main application's app.config file?

Thank you,

Alan
Nov 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Alan,

Class libraries can not have their own app config files (unless they are
the entry points, in some cases). They defer to the application
configuration file of the executing application.

You should place your configuration section in your app.config file for
the application that uses the library. This is in the case where different
applications can use the library in a different manner and you want to
configure that in the app.config file.

If the settings do not change across application instances, then you
should probably just have a file in the directory where the class library is
installed and read from that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ca*******@caspershouse.com

"A.M-SG" <al******@newsgroup.nospam> wrote in message
news:e8**************@TK2MSFTNGP14.phx.gbl...

Hi,

We have a class library application that needs to read some application
settings from it's own app.config file.

I assume that a ClassLibrary.DLL can have a app.config file, but during
runtime, it run within the context of another main application that has
its own app.config file (am I correct?)

My main question is how can I control a ClassLibrary.DLL to read its own
app.config or the main application's app.config file?

Thank you,

Alan

Nov 17 '05 #2

P: n/a
Thank you for help.
If the settings do not change across application instances, then you
should probably just have a file in the directory where the class library
is installed and read from that.
Do you mean to have an app.config file in the ClassLib directory ? or a
custom XML file to store setting?

Thank you again,
Alan


"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl... Alan,

Class libraries can not have their own app config files (unless they
are the entry points, in some cases). They defer to the application
configuration file of the executing application.

You should place your configuration section in your app.config file for
the application that uses the library. This is in the case where
different applications can use the library in a different manner and you
want to configure that in the app.config file.

If the settings do not change across application instances, then you
should probably just have a file in the directory where the class library
is installed and read from that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ca*******@caspershouse.com

"A.M-SG" <al******@newsgroup.nospam> wrote in message
news:e8**************@TK2MSFTNGP14.phx.gbl...

Hi,

We have a class library application that needs to read some application
settings from it's own app.config file.

I assume that a ClassLibrary.DLL can have a app.config file, but during
runtime, it run within the context of another main application that has
its own app.config file (am I correct?)

My main question is how can I control a ClassLibrary.DLL to read its own
app.config or the main application's app.config file?

Thank you,

Alan


Nov 17 '05 #3

P: n/a
Hi,

I assume that a ClassLibrary.DLL can have a app.config file, but during
runtime, it run within the context of another main application that has
its own app.config file (am I correct?)

Wrong, they do not.

I have a similar situation, I have a DLL that is a command for ArcGIS and
need to store some config values, even more, this values should be
particular to each users.
I create a folder under ApplicationData using :
System.Environment.GetFolderPath(Environment.Speci alFolder.ApplicationData);

There I store my config file.
For the config you have several options, if you prefer something like the
"regular" config, you could use a Hashtable and serialize it, then you can
use it like Config["Key"] = value;
Or as I did, I only have 5 values, so I used instead a text file in the form
key=value , I open, read and parse it and I make available those variables
as static properties.
I don't need to save them back, so it's even easier.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Nov 17 '05 #4

P: n/a
Hi Alan,

We can not apply an app.config file to the class library dll. Because just
as the name implied, this configuration file is for the application wide.

I think what "Nicholas Paldino [.NET/C# MVP]" sugggested is to place the
class library configuration sections into the app.config file where your
application is in. Then your class library code can read the configuration
without any problem.

If you still want a customized config file for class library so that we
need not copy the config information to all the applications using the dll,
I think we have to store the configuration information in a XML file, then
use System.Xml namespace classes to read this XML config file.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #5

P: n/a
Hi Alan,

Does my reply make sense to you? If you still have any concern, please feel
free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #6

P: n/a
Hi Jeffrey,

Yes, your reply helped me.

Thanks alot,
Alan

""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:gR**************@TK2MSFTNGXA01.phx.gbl...
Hi Alan,

Does my reply make sense to you? If you still have any concern, please
feel
free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #7

P: n/a
It is my pleasure to help you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.