views:

54

answers:

1

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 seperate 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!

+2  A: 

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.

David Morton
I've set the line to <section name="ReportEngineConfig" type="Optima.ReportEngine.ReportEngineConfig, ReportEngine" allowDefinition="Everywhere" allowLocation="true"/> with ReportEngine being the name of the dll but this["value"] still gets a null reference?
mjmcloug