ClassLibrary.DLL and app.config files

A

A.M-SG

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
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
A

A.M-SG

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 said:
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]
- (e-mail address removed)

A.M-SG said:
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
 
I

Ignacio Machin \( .NET/ C# MVP \)

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.SpecialFolder.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,
 
J

Jeffrey Tan[MSFT]

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.
 
J

Jeffrey Tan[MSFT]

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.
 
J

Jeffrey Tan[MSFT]

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.
 

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