473,842 Members | 1,535 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 13681
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
8316
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
7694
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
8315
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
10744
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
4776
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
5809
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
1012
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
1273
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
3625
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
10614
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
10317
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
9454
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...
1
7859
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
7040
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
5697
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...
1
4500
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4090
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3146
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.