Custom configuration file with an IConfigurationSectionHandler

M

mrshrinkray

Hi all,

I'm trying to write tests for a custom section of a .config file. I
need to tell the ConfigurationManager to use the invalid app.config
file, in order to make sure my validation of config file is working.

This is what I've got, but I can't get the ConfigurationManager to use
my IConfigurationSectionHandler class.

ExeConfigurationFileMap exeConfig = new ExeConfigurationFileMap();
exeConfig.ExeConfigFilename = @"c:\path\InvalidApp.config";
Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(exeConfig,
ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection("mysection");

I need the equivalent of ConfigurationManager.GetSection("mysection");

I also get the problem that the test refuses to copy my
InvalidApp.config to its "Out" directory when it runs, so I'm hard
coding it for now.
 
N

nologo

Hi all,

I'm trying to write tests for a custom section of a .config file. I
need to tell the ConfigurationManager to use the invalid app.config
file, in order to make sure my validation of config file is working.

This is what I've got, but I can't get the ConfigurationManager to use
my IConfigurationSectionHandler class.

ExeConfigurationFileMap exeConfig = new ExeConfigurationFileMap();
exeConfig.ExeConfigFilename = @"c:\path\InvalidApp.config";
Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(exeConfig,
ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection("mysection");

I need the equivalent of ConfigurationManager.GetSection("mysection");

I also get the problem that the test refuses to copy my
InvalidApp.config to its "Out" directory when it runs, so I'm hard
coding it for now.

Well firstly, you need to copy the config file to the bin\Debug file
manually. when creating the package you need to select that config at
that time as well.

For your issue regarding using the config file, have you called:
using System.Configuration;
?
 
M

mrshrinkray

Well firstly, you need to copy the config file to the bin\Debug file
manually. when creating the package you need to select that config at
that time as well.

For your issue regarding using the config file, have you called:
using System.Configuration;
?

The tests (for VS Team System) get moved to ..\testresults\user-date
\out , changing the Build Action has no effect on the file being
copied there.

As far as the using clause, it wouldn't compile without it so I have
got that in. My problem is coming from getting ConfigurationSection
back instead of the object my IConfigurationSectionHandler class
passes back.
 

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