473,739 Members | 5,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Configuration Model in .Net 2.0

Hi all,
I understand, in .Net 2.0 we have little bit different model to read
config file from .Net 1.1. Basically I need to use
WebConfiguratio nManager.AppSet tings to read from web.config, and
ConfigurationMa nager.AppSettin gs to read from Windows Application config.
Here is my question, I have a class library project which will be
referenced by both Web and Windows Application in different projects, I need
to read config setting inside this class library, how should I know which
environment is it in (web or windows) and based on environment to call
different API to load setting? And what is the best practice in this
scenario to handle config file?

--
WWW: http://www.imagestation.com/members/hardywang
ICQ: 3359839
yours Hardy
Sep 29 '06 #1
5 2933
Hi,

I am sorry to say that I don't think you should read or write app.config or
web.config file in a class library. Configuration file doesn't make sense
for a class library.

Suppose we have a class library project and a Windows application project.
We add a configuration file and access it within the class library project
and build the class library project. We add a reference to the class
library project in the Windows application project and then build the
Windows application project. You will see that the configuration file of
the class library project isn't copied to the 'bin\debug' directory of the
Windows application project.

The class library won't read value of the settings from its configuration
file, instead it will adopt the default value. Even if we copy the
configuration file of the class library to the 'bin\debug' directory of the
Windows application project and modify the value of the settings in the
configuration file, the class library won't see the new value of the
settings.

So we should add and access application settings in the Windows application
or Web application project.

Hope this helps.

If you have any concerns, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 2 '06 #2
Hi Linda,
Thanks for your reply, I think I did not make myself clear.

What I am talking is, class library reads configuration from either
web.config or Application.exe .config. For example, there is a key named
"Email" in web.config for my web application, in Application.exe .config for
my Application.exe windows form application. The class library doesn't
include any config file with it, it just reads this key in both environments.

"Linda Liu [MSFT]" wrote:
Hi,

I am sorry to say that I don't think you should read or write app.config or
web.config file in a class library. Configuration file doesn't make sense
for a class library.

Suppose we have a class library project and a Windows application project.
We add a configuration file and access it within the class library project
and build the class library project. We add a reference to the class
library project in the Windows application project and then build the
Windows application project. You will see that the configuration file of
the class library project isn't copied to the 'bin\debug' directory of the
Windows application project.

The class library won't read value of the settings from its configuration
file, instead it will adopt the default value. Even if we copy the
configuration file of the class library to the 'bin\debug' directory of the
Windows application project and modify the value of the settings in the
configuration file, the class library won't see the new value of the
settings.

So we should add and access application settings in the Windows application
or Web application project.

Hope this helps.

If you have any concerns, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 5 '06 #3
Hi Hardy,

Thank you for your update and the clarification of the problem.

Firstly, I don't think we could read&write the configuration file of
project A in project B using AppSettings. But if we treat the configuration
file as a normal XML file in project B(I mean use XML DOM to access the
file), we can access the configuration file of project A in project B.

Secondly, since the configuration is used by the class library, I recommend
you to define the configuration file by yourself (don't use the
configuration file that is generated automatically by VS when we add
application settings in the Windows or Web projects). Thus, no matter which
type of the project the class library is refereced to, the class library
will access the same configuration file.

Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support

Oct 6 '06 #4
Hi Hardy,

How about your solving the problem now?

I have done more research on this problem and found that I made a mistake
in my previous reply. I was focusing on reading the configuration file with
the strongly typed settings class generated by the
SettingsSingleF ileGenerator custom tool, which is associated with settings
files by default. I meant it's no possible to read the configuration file
of the Windows application or Web application from the class library using
the strong typed settings class.

If we use ConfigurationMa nager class, we could access any configuration
file as long as we specify the filename of the configuration file.

As for the question how to know which environment is the class library in,
I don't think there's a easy way to do that. But I think there's a simple
way. Suppose there's a function in the class library to read configuration
files. We could add a parameter in the function to specify which type of
the config file is. When we call the function from the Windows application
or Web application, pass a value to the parameter to specify the type of
the configuration file.

Hope this helps.
If you have any concerns, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Oct 12 '06 #5
I too need this functionality. My class library needs to be able to
read some configuration settings and have it automatically come from
the app.config or web.config depending on whether the application using
the class library is a Windows or ASP.NET application.

Nov 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1547
by: Gary | last post by:
I am working with a report generator that is based on SQL Server 2000 and uses ASP as the UI. Basically we have a set of reports that end users can execute through a web browser. In general the model works fine, but we are running into some scaling issues. What I'm trying to determine is, what is the optimal configuration for this system. It is currently a 2.4G Pentium with a large RAID and 1G of RAM. We have been using the "fixed"...
3
1926
by: Robert | last post by:
I have an application with custom configuration sections in it's app.config file. Here's a shortened excerpt: <monitors> <monitor type="SystemMonitor.Monitors.NetworkAvailabilityMonitor,SystemMonitor"> <notifiers> <notifier type="SystemMonitor.Notifiers.MessageBoxNotifier,SystemMonitor" />
4
5775
by: Oliver Stratmann | last post by:
Hello All, does anyone know, where the configuration of a db2-client on a windows-machine is stored? I searched the registry and the filesystem on my machine and couldn't find anything. Is there a file or a node in the registry, where all the information (like port-number, db-name and so on) can be found. Is there another place for this piece of information?
8
1587
by: Shimon Sim | last post by:
Hi I converted my existing ASP.NET project to VS.NET 2005. Build gives me some warnings about config file. I have custom section definition in web.config. Were there any changes in this for ASP.NET 2.0. Where can I see what was change and how I can migrate? Thank you Shimon.
1
1175
by: Philip Wagenaar | last post by:
Hi, I used the microsoft configuration block to store settings for applications in the past and this worked fine. But now I have the following situation and I do not know how to solve this: I want to write a windows service that stores its settings in a xml file using the configuration block. And I want to write a windows forms application that manages the service. Stop,start and modify the settings.
10
3730
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server Error in '/QuickStartv20' Application. -------------------------------------------------------------------------------- Configuration Error Description: An error occurred during the processing of a configuration file
7
2849
by: Inga2005 | last post by:
I have developed an web site in VS2005 but I can't build a release version since the option is missing in the configuration manager. The second thing is that there isn't a bin folder placed in my project. Anybody knows how to solve this.
1
3353
by: Peter Kirk | last post by:
Hi I was wondering if anyone had experience of using the "provider model" in ..net. I have only just stumbled across this pattern/model and am trying to evaluate if it is worth while learning and using it. Basically all the projects I work on have a data persistence layer (which seems to be what the .net provider model is about?), and we generally build our systems up in "pluggable modules" which theoretically means we could swap out...
1
1369
by: Michael Lang | last post by:
Any suggestions on how you can load an arbitrary number of unknown attributes on an element in a custom section in the .config into a NameValueCollection ? Basically I want to do something similiar to what occurs with a System.Configuration.Provider.ProviderBase Initialise method - the provider is passed a NameValueCollection containing attribute names and their associated values from the .config. see... ...
0
8969
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8792
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.