app.config changes not being saved

E

Eric

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(ConfigurationUserLevel.None); is
how you get hold of it.

Thanks for helping - Eric

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

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

APP.CONFIG
 
H

Hans Kesting

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(ConfigurationUserLevel.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
 
E

Eric

I looked at (read) the original app.config file. Isn't that where changes
should be?
 
H

Hans Kesting

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top