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

How to use config file in classlibrary project (dll).

P: n/a
Hi!
I´m creating a classlibrary project. The output will be a dll. This dll will
have to read some settings from some kind of config-file. Normally, when
creating a standard .exe-program I use the app.config file. Which is the best
approach to use when creating a classlibrary? Please give me some eaxmple.

I´m using VB.NET 2.0

Best regards
/ Stefan

Mar 21 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi Steve,

Different from the .NET executable application, a .NET classlibrary does
not have its own app config file.

To workaround this problem, I suggest you can emerge your classlibrary's
configuration section data into the target app.config file of the
application that uses that class library.

If you would not like use the target application's app.config file, you
could also use a stand-alone file to put its configuration data. In this
case, you need to put that file in the directory where the class library is
installed.

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 22 '06 #2

P: n/a
Thanks Gary!
I do not have access to any config of the exefile. So I have to go with your
second suggestion. Should I create a standard .xml-file to read as a
xmldocument or should I use a .config-file? Can I read it in an easy way.
Please give me an example. If I put it in the folder where the classlibrary
is installed how can I read it from the code?

""Gary Chang[MSFT]"" wrote:
Hi Steve,

Different from the .NET executable application, a .NET classlibrary does
not have its own app config file.

To workaround this problem, I suggest you can emerge your classlibrary's
configuration section data into the target app.config file of the
application that uses that class library.

If you would not like use the target application's app.config file, you
could also use a stand-alone file to put its configuration data. In this
case, you need to put that file in the directory where the class library is
installed.

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 22 '06 #3

P: n/a
Hi Steve,
Should I create a standard .xml-file to read as a
xmldocument or should I use a .config-file?


No particular .config file for a classlibrary. Just use a standard xml file
and manipulate it as a normal xml file.

Thanks!

Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 22 '06 #4

P: n/a
Ok thanks Gary.
I want the .xml-file to be in the folder where the .dll is installed. My
installationprogram will register the dll in the GAC and another program will
use late binding, like Assembly.Load(myDLL) to load this dll-assembly. My
question is how can I specify the path of the .xml-file in the dll? If I use
like myXmlDocument.Load("myConfig.xml") the app which tries to load the
dll-assembly looks for the .xml-file in the "working folder" of the app. I
want it to look in the installationfolder of the dll. Can this be done,
without hard-coding the path to installationfolder for the dll?

Thanks
/ Stefan

"Stefan" wrote:
Hi!
I´m creating a classlibrary project. The output will be a dll. This dll will
have to read some settings from some kind of config-file. Normally, when
creating a standard .exe-program I use the app.config file. Which is the best
approach to use when creating a classlibrary? Please give me some eaxmple.

I´m using VB.NET 2.0

Best regards
/ Stefan

Mar 24 '06 #5

P: n/a
Hi Stefan,
My question is how can I specify the path of
the .xml-file in the dll?


I suggest you try the following sample code first:

myXmlDocument.Load(".\\myConfig.xml")

Wish it works!
Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 27 '06 #6

P: n/a
Hi again Gary!
It didn´t work to use the path like myXmlDocument.Load(".\\myConfig.xml").
If this isn´t possible I guess I can get access to app.config of the main app.
I have tryied this but can´t seem to get it work correctly. I´m trying to
use the new My.Settings syntax from the dll. The dll-library will be in the
gac and then used by the app.
Can you please give me a codeexample on how to read settings from the
app.config of the main-app from the classlibrary.

Ps. To be able to compile the classlibrary I have to have a app.config in
the solution of the classlibrary to. This because the my.settings. is
strongly typed. Now I get the value of the setting from this app.config
instead of the one from the main app. How is this possible. Is the settings
being embedded in the dll someway. The dll is in the gac. Seem strange to me.

Thanks in advance
/ Stefan

""Gary Chang[MSFT]"" wrote:
Hi Stefan,
My question is how can I specify the path of
the .xml-file in the dll?


I suggest you try the following sample code first:

myXmlDocument.Load(".\\myConfig.xml")

Wish it works!
Best regards,

Gary Chang
Microsoft Community Support
================================================== ====
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00
AM PST, February 14, 2006. Please complete a re-registration process by
entering the secure code mmpng06 when prompted. Once you have entered the
secure code mmpng06, you will be able to update your profile and access the
partner newsgroups.
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 20 '06 #7

P: n/a
Hi Stefan,
It didn't work to use the path like myXmlDocument.Load(".\\myConfig.xml").
This is because your class library is strong named, but you cannot put that
corresponding myConfig.xml file to the GAC. In this point, I think you can
install that configuration file to another well-known directory, and use
the Windows system variables to access that directory (e.g.
%windir%\\...\\myConfig.xml).
Can you please give me a codeexample on how to
read settings from the app.config of the main-app
from the classlibrary.


If you want to use the app.config of the main-app, you can read the app's
settings from the class library as same as from the app itself. There
doesn't exist any difference. Just use the
ConfigurationSettings.AppSettings to retrieve the target setting from the
app's app.config. You will find many samples in the web on how to read
app.config from the application itself

By the way, I suggest you can refer to the following newsgroup thread,
which also ahs a detailed discussion on the same topic:

http://groups.google.com/group/micro...es.csharp/brow
se_frm/thread/7190ac9a4da8563c/a8a2fd7cbf5f026a?lnk=st&q=read+app.config+fro
m+classlibrary&rnum=2&hl=en#a8a2fd7cbf5f026a
Thanks!

Best regards,

Gary Chang
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 21 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.