How to define a ConfigurationSection
So this a new one for me.
I'm trying to define a ConfigurationSection class in my class library that pulls from App.Config in my WinForms app. I've never done this before but from following examples this is where I've got to.
app.config in my WinForms app
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="ReportEngineConfig" type="Optima.ReportEngine.ReportEngineConfig" allowDefinition="Everywhere" allowLocation="true"/>
</configSections>
<ReportEngineConfig>
<ReportObjectVariableRegEx value="test" ></ReportObjectVariableRegEx>
</ReportEngineConfig>
</configuration>
And my ConfigurationSection class in my s开发者_JAVA百科eperate class library.
using System.Configuration;
namespace Optima.ReportEngine
{
public class ReportEngineConfig : ConfigurationSection
{
[ConfigurationProperty("ReportObjectVariableRegEx")]
public string ReportObjectVariableRegEx
{
get
{
return (string)this["value"];
}
}
}
}
So any chance anyone can point out where I've gone wrong
Thanks!
Your type tag needs to reference the assembly name, not just the type name:
type="Optima.ReportEngine.ReportEngineConfig, Optima.ReportEngineAssembly"
Where the section after the comma is the name of the assembly containing ReportEngineConfig. You'll also have to make sure the application that is using this app.config has referenced the same assembly containing ReportEngineConfig.
Also you can get rid of the allowDefinition and allowLocation tags... you've put the defaults in.
精彩评论