473,748 Members | 11,134 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 13660
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
7690
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
10738
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
5795
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
1007
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
1268
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
3622
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
8989
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
8828
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
9537
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
9367
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
6795
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
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
4599
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4869
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2780
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.