By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,456 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,456 IT Pros & Developers. It's quick & easy.

app.config changes not being saved

P: n/a
I'm trying to manipulae my app.config file. Below is code to test that I can
remove a ConfigurationSection. It looks like its working, but the app.config
file is not changed when I look at it after.

I think it has something to do with the file path; the .FilePath returned
<C:\Projects\MyProject\src\Core.Tests\bin\Debug\My Project.Core.Tests.dll.temp.config>
isn't app.config but I've seen a couple of places that say that
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None); is
how you get hold of it.

Thanks for helping - Eric

CODE
------
[Test]
public void RemoveASection() {
var config =
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);
var groups = config.Sections;
Console.WriteLine(config.FilePath);

if
(config.Sections[DomainObjectMappingConstants.ConfigurationSectionN ame] !=
null) {
var section =
config.Sections[DomainObjectMappingConstants.ConfigurationSectionN ame] ;
Assert.That(section.SectionInformation.Name,
Is.EqualTo(DomainObjectMappingConstants.Configurat ionSectionName));
groups.Remove(section.SectionInformation.Name);
config.Save(ConfigurationSaveMode.Full);
Assert.That(config.Sections[DomainObjectMappingConstants.ConfigurationSectionN ame]
== null);
}
}

APP.CONFIG
---------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
------------
<section name="domainObjectMappingsConfiguration"
type="Core.Domain.FactoryFramework.Configuration.D omainMapSettings,
Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
------------
</configSections>

</configuration>
Aug 3 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Eric submitted this idea :
I'm trying to manipulae my app.config file. Below is code to test that I can
remove a ConfigurationSection. It looks like its working, but the app.config
file is not changed when I look at it after.

I think it has something to do with the file path; the .FilePath returned
<C:\Projects\MyProject\src\Core.Tests\bin\Debug\My Project.Core.Tests.dll.temp.config>
isn't app.config but I've seen a couple of places that say that
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None); is
how you get hold of it.
The file that is named app.config in your VS project is renamed to
<assemblyoutput>.config and copied to the build-directory when you
compile the project. I don't know where the ".temp" part is coming
from.

Did you read *that* file after the test was run, or your original
"app.config" file? Any changes will not be copied back...

Hans Kesting
Aug 4 '08 #2

P: n/a
I looked at (read) the original app.config file. Isn't that where changes
should be?
"Hans Kesting" <ne*********@spamgourmet.comwrote in message
news:Od**************@TK2MSFTNGP05.phx.gbl...
Eric submitted this idea :
>I'm trying to manipulae my app.config file. Below is code to test that I
can remove a ConfigurationSection. It looks like its working, but the
app.config file is not changed when I look at it after.

I think it has something to do with the file path; the .FilePath returned
<C:\Projects\MyProject\src\Core.Tests\bin\Debug\M yProject.Core.Tests.dll.temp.config>
isn't app.config but I've seen a couple of places that say that
ConfigurationManager.OpenExeConfiguration(Configu rationUserLevel.None);
is how you get hold of it.

The file that is named app.config in your VS project is renamed to
<assemblyoutput>.config and copied to the build-directory when you compile
the project. I don't know where the ".temp" part is coming from.

Did you read *that* file after the test was run, or your original
"app.config" file? Any changes will not be copied back...

Hans Kesting


Aug 5 '08 #3

P: n/a
Eric formulated on dinsdag :
I looked at (read) the original app.config file. Isn't that where changes
should be?
No, that file is copied to the build directory and renamed. See your
returned "FilePath" - do you see your changes in *that* file?
This is identical to the "live" situation: there you also don't have
that "app.config" anywhere, just the renamed version: full name of the
project output (including a .dll or .exe extension) plus the (extra)
..config extension.

Hans Kesting
>
"Hans Kesting" <ne*********@spamgourmet.comwrote in message
news:Od**************@TK2MSFTNGP05.phx.gbl...
>Eric submitted this idea :
>>I'm trying to manipulae my app.config file. Below is code to test that I
can remove a ConfigurationSection. It looks like its working, but the
app.config file is not changed when I look at it after.

I think it has something to do with the file path; the .FilePath returned
<C:\Projects\MyProject\src\Core.Tests\bin\Debug\ MyProject.Core.Tests.dll.temp.config>
isn't app.config but I've seen a couple of places that say that
ConfigurationManager.OpenExeConfiguration(Config urationUserLevel.None); is
how you get hold of it.

The file that is named app.config in your VS project is renamed to
<assemblyoutput>.config and copied to the build-directory when you compile
the project. I don't know where the ".temp" part is coming from.

Did you read *that* file after the test was run, or your original
"app.config" file? Any changes will not be copied back...

Hans Kesting


Aug 5 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.