TY Cecil;
I have a class library in which I have some file manipulation and datbase
access methods. The objective is to install the library as XP on SQL Server
and it is greatly desired to have a config file so as to control some
pathnames and control varibales. If I include the Class library with a
project (say a win app), I can read read the App.Config file from the the
class library without any problems. If I try to use a app.config with class
library assembly, then code such as
ConfigurationSettings.AppSettings["ErrorLogFile"] no longer returns any
values. In fact, an exception is thrown if i try.
Is there some way to associate a config file with the class library
assembly? I looked at the documentation on customizing assemblies, but it is
not clear to me how to associate a config file with the class library
assembly.
Any help will be appreciated.
AlanS
> Alan,
> What kind of problems are you having? A class library can
> certainly have a config file and if it is not working for you no one
> can help you with out knowing what the problem is.
> cecil Howell MCSD, MCT
cecil@ceciltech.com - 16 Dec 2004 23:52 GMT
Alan,
Your config file needs to be in the same folder as the dll was
loaded from and needs to be named identically to the dll ie dll =
util.dll config = util.dll.config
I could maybe tell you more but you did not specify what the exception
was that was thrown, you need to help us help you! If you are going to
post you need to start including specifics about what you are doing and
what is going wrong. You will find people will be quicker to help and
you will likely solve your problem if you include some details when you
post.
Cecil Howell MCSD, MCT
> TY Cecil;
>
> I have a class library in which I have some file manipulation and datbase
> access methods. The objective is to install the library as XP on SQL Server
> and it is greatly desired to have a config file so as to control some
> pathnames and control varibales. If I include the Class library with a
> project (say a win app), I can read read the App.Config file from the the
[quoted text clipped - 6 lines]
> assembly? I looked at the documentation on customizing assemblies, but it is
> not clear to me how to associate a config file with the class library
> assembly.
>
[quoted text clipped - 7 lines]
> > can help you with out knowing what the problem is.
> > cecil Howell MCSD, MCT
Marc Scheuner [MVP ADSI] - 17 Dec 2004 09:12 GMT
>Your config file needs to be in the same folder as the dll was
>loaded from and needs to be named identically to the dll ie dll =
>util.dll config = util.dll.config
BUT: the .NET System.Configuration.ConfigurationSettings class will
*NOT* work on this .config file! You will *NOT* be able to retrieve
values from it!
The ConfigurationSettings class will *ONLY* work on the app's
"MyApp.exe.config" that is calling that particular DLL.
If you want to use a config file for your DLL, you'll need to "roll
your own" - there's quite a few samples of how to do this on e.g.
www.codeproject.com.
Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Richard Grimes [MVP] - 20 Dec 2004 21:52 GMT
> XP on SQL Server and it is greatly desired to have a config file so
> as to control some pathnames and control varibales. If I include the
If you use the framework config API this data must be in the app's config
file or in machine.config.
> Class library with a project (say a win app), I can read read the
> App.Config file from the the class library without any problems. If
That's the intended behaviour.
> I try to use a app.config with class library assembly, then code such
> as ConfigurationSettings.AppSettings["ErrorLogFile"] no longer
> returns any values. In fact, an exception is thrown if i try.
Nope.
The reason is that the AppDomain is created with the name of the config
file, once the AppDomain is created you cannot change the name of the config
file. The default name of the config file is <app file name>.config.
However, if you create a new AppDomain you can tell it to use any config
file you specify, but I don't think that you want to do this!
> Is there some way to associate a config file with the class library
> assembly? I looked at the documentation on customizing assemblies,
> but it is not clear to me how to associate a config file with the
> class library assembly.
If all you want to do is to control "some pathnames and control varibales"
then you could create a class with these as public properties and then use
the XmlSerializer class to serialize/deserialize instances of this class to
an XML class. If you are doing this, then you store this file in isolated
storage if the data is associated with a user, or to the application's
folder if the data is not user specific.
Richard

Signature
.NET training, development, consulting and mentoring
www.richardgrimes.com
my email evpuneqt@zicf.bet is encrypted with ROT13 (www.rot13.org)