Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / December 2004

Tip: Looking for answers? Try searching our database.

Newbie question: DLLs and Config files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
AlanS - 15 Dec 2004 18:17 GMT
I have used application configuration files with windows and web apps.  Now I
would like to create a class library and associate a config file with the
DLL.  This is to support directory changes that will take place in the
future.  I want to put directory pathnames in the config file and read then
from the DLL methods.  When I try to use an app.config with class library i
have problems.  Any suggestions?
jdmartinez@ea.com - 15 Dec 2004 18:50 GMT
I'm fairly certain that you cannot use a .config with a .dll.  It only
works with executables (ie. you can't have mylib.dll.config).  You're
just going to have to include the configuration settings the
executable's configuration file.

Joel Martinez
http://www.onetug.org - Orlando .NET User Group
http://www.codecube.net - blog
cecil@ceciltech.com - 15 Dec 2004 20:12 GMT
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
AlanS - 15 Dec 2004 20:29 GMT
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)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.