473,763 Members | 7,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using ConfigurationMa nager to modify another project's app.config

I have a solution with two projects. Project A is the startup
project, while Project B serves as the project with the data logic.

At run time, the first thing I need to do is write to Project B's
app.config. I've referenced System.configur ation.dll within Project
B, and from one of the classes inside Project B's namespace, I'm
trying to use ConfigurationMa nager to write to its app.config.
Unfortunately, it only finds Project A's app.config. I've even tried
removing Project A's app.config file, but it still can't "see" Project
B's app.config.

Is there any way to accomplish this?
Jun 27 '08 #1
3 13667
The reason you cannot see the other project's app.config directly from
ConfigurationMa nager is because when the appdomain is loaded the (i would
imagine) .net framework decides which configuration file that application
should use.

You can access other application configuration files by opening them
directly and then accessing the information in them using the configuration
manager class.

using System.Configur ation;

string path = "C:\\MyExecutab le.exe"; // The path must be that of your
executable, not the path of the config file.
Configuration config = ConfigurationMa nager.OpenExeCo nfiguration(pat h);

Once the file has been opened, you'll be able to modify it similarly to how
you would normally access the data. Once you're done accessing it just call
the config.Save(); method or the appropriate overload your application
requires. Keep in mind, modifying an application's config file while it's
running will not change the configuration that gets cached once the
ConfigurationMa nager has been used.

Meaning: if you start project A, and then start project B - use the
ConfigurationMa nager in project B to access some data in it, and then have
project A modify the configuration for project B - project B's configuration
will not update until the appdomain is reloaded.

HTH,
- Jeff
"Jeff" wrote:
I have a solution with two projects. Project A is the startup
project, while Project B serves as the project with the data logic.

At run time, the first thing I need to do is write to Project B's
app.config. I've referenced System.configur ation.dll within Project
B, and from one of the classes inside Project B's namespace, I'm
trying to use ConfigurationMa nager to write to its app.config.
Unfortunately, it only finds Project A's app.config. I've even tried
removing Project A's app.config file, but it still can't "see" Project
B's app.config.

Is there any way to accomplish this?
Jun 27 '08 #2
If you have a solution with an executable that references some class library
that is in another project in the solution, consider keeping all your
configuration information in the config file for the executable project.
Code in your class library will be able to "see" all the configuration data
from the main program. Keep it simple.
Peter
"Jeff" <jr***@usa.netw rote in message
news:ef******** *************** ***********@e39 g2000hsf.google groups.com...
>I have a solution with two projects. Project A is the startup
project, while Project B serves as the project with the data logic.

At run time, the first thing I need to do is write to Project B's
app.config. I've referenced System.configur ation.dll within Project
B, and from one of the classes inside Project B's namespace, I'm
trying to use ConfigurationMa nager to write to its app.config.
Unfortunately, it only finds Project A's app.config. I've even tried
removing Project A's app.config file, but it still can't "see" Project
B's app.config.

Is there any way to accomplish this?
Jun 27 '08 #3
Hi,
i tried the way that u guided but it pops this build error:

Error 'System.Configu ration.Configur ationElement.th is[System.Configur at
ion.Configurati onProperty]' is inaccessible due to its protection level

how can i change the protection level of config file to resolve the
issue?

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #4

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

Similar topics

1
8313
by: MC | last post by:
Hi folks. Having a slight problem with ConfigurationManager in Visual Basic Express Edition 2005. Its claiming the Name ConfigurationManager is not declared. It works fine in Visual Web Express but not when trying to use my connectionstring in my app.config file. I am using the following line:
2
7691
by: robertino | last post by:
Hi All, (VS 2005 Pro, Win XP Pro) I'm trying to read some app settings from my app.config file (normal Win app), have included the System.Configuration namespace in my app, but when I try to access the ConfigurationManager class, I find no mention of it at all! According to the online help, ConfigurationManager is the preferred way to go to access the appSettings information ("all other methods are
4
8312
by: Ron Gliane | last post by:
From the documentation I could find, it seems that reading “appSettings” from the app.config file is now done through ConfigurationManager.AppSettings for ..NET 2.0, instead of the obsolete ConfigurationSetting.AppSettings. But what’s kind of confusing is that “appSetttings” itself seems to be in disfavor. Accessing “applicationSettings” using My.Settings seems to be the preferred way. 1st question: Is My.Settings...
3
10741
by: natasha | last post by:
Hello everybody, you can use ConfigurationManager.AppSettings.Set method (ConfigurationManager is in System.Web.Configuration namespace) to store a modified value from web.config. To be practical, you define a custom key in web.config: <appSettings> <add key="ReportButtonClick" value="0" /> </appSettings>
6
4770
by: TS | last post by:
I cannot get this to work. I added an app.config to a project i reference from my web application project (vs 05) but can see no way to access the settings within it. the other thing is that I expected this config file (.dll.config) to get put in my web app's bin folder along with it's .dll file when i did a build, and that didnt' happen either. do I have access to the app.config in my project or is it worthless? If so why can i add...
0
5798
by: Jeremy Noring | last post by:
Hi, I have an application that loads various settings from the app.exe.config file. This has worked very well on w2k, XP, and Vista. However, recently I've been troubleshooting an issue on Windows Home Server (which is based on some variation of Windows Server 2003) and I've found that ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel) is
1
1008
nev
by: nev | last post by:
'this code can be used to modify the connectionstring for those who use the 'dataset designer to make their programs. Public Shared Sub SetConnectString(ByVal SectName As String, ByVal ConnectString As String, ByVal encrypt As Boolean) Dim settings As New ConnectionStringSettings settings.Name = SectName settings.ConnectionString = ConnectString Dim config As Configuration config =
0
1270
by: Tom | last post by:
This seems odd ... While debugging my application in VS2008, I can successfully retrieve values from my configuration file doing the following: string bla = ConfigurationManager.AppSettings; I can also successfully save to the config file doing the following: Configuration c =
2
3623
by: moorcroft | last post by:
I have a .Net web service solution set up and it has about 8 projects within the solution. One of the projects is the main host project and it contains the web.config that I wish to use for the solution configuration. I'm wondering how System.Configuration.ConfigurationManager knows how to look in this config file for settings as it currently does not seem to look in here..
0
9564
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9387
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
10148
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
10002
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...
0
9823
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
8822
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 projectplanning, coding, testing, and deploymentwithout 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
6643
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();...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2794
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.