473,405 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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

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
7 10101
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Cantekin Guneser | last post by:
hi firsly, i have one projec that is clas library project (dll project). i have config file for this project an i am using appsetting section. until here no problem i wantto use this dll in a web...
7
by: A.M-SG | last post by:
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...
3
by: Christopher Kimbell | last post by:
I have a class library that contains a number of TableAdapters and I'm using this from a web application. Is there a way of getting the TableAdapters to use the connectionstrings defined in...
2
by: Keith Elder | last post by:
Let's say you have a stand alone C# library project that is your datalayer. When this library compiles it will produce "My.DataLayer.dll" for example. In the project you use all the new...
3
by: Søren M. Olesen | last post by:
Hi I've created a Class library (myClasses.dll), and added a settings.settings to it using designer. However when I use this class library, it doesn't seem to read the settings...
5
by: ad | last post by:
I am developing web applicaiton with VS2005. The WebApp used a ClassLibrary in another project. There are some TableAdapter in the classlibrary, and the TableAdapter use the connection in the...
5
by: mark_overstreet | last post by:
I have a generic data layer DLL that expects to read its connection string from it's own config file. The dll and config file have been placed in the bin directory (VS.NET2005). However, due to...
12
by: dbuchanan | last post by:
Hello, (Is this the proper newsgroup?) === Background === I am building a solution with two projects. One project is my data access layer which contains my DataSet as an xsd file. The XSD...
1
by: huntco | last post by:
VS2005, .Net 2.x I've built a .dll from the classlibrary template. Everything works great on the development box. When moving it over to the production box, I started getting database connection...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.