2010-02-25 2 views
2

이렇게 나를 위해 새로운 것.ConfigurationSection을 정의하는 방법

내 WinForms 응용 프로그램의 App.Config에서 가져 오는 클래스 라이브러리에서 ConfigurationSection 클래스를 정의하려고합니다. 나는 전에 이것을 한 번도 해보지 않았지만 다음 예제에서 이것은 내가해야 할 곳이다.

내 윈폼 응용 프로그램

<?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> 

에서

의 app.config 그리고 내 별도의 클래스 라이브러리 내없는 ConfigurationSection 클래스입니다.

using System.Configuration; 내가

감사합니다 잘못 갔어요 곳

namespace Optima.ReportEngine 
{ 
    public class ReportEngineConfig : ConfigurationSection 
    { 
     [ConfigurationProperty("ReportObjectVariableRegEx")] 
     public string ReportObjectVariableRegEx 
     { 
      get 
      { 
       return (string)this["value"]; 
      } 
     } 

    } 
} 

그래서 어떤 기회 누구나 지적 할 수 있습니다!

답변

2

귀하의 유형 태그는 단지 형식 이름, 어셈블리 이름을 참조 할 필요가 :

쉼표 후 섹션을 ReportEngineConfig이 들어있는 어셈블리의 이름입니다
type="Optima.ReportEngine.ReportEngineConfig, Optima.ReportEngineAssembly" 

. 또한이 app.config를 사용하는 응용 프로그램이 ReportEngineConfig가 포함 된 동일한 어셈블리를 참조했는지 확인해야합니다.

또한

당신이 allowDefinition과를 allowLocation 태그를 제거 할 수 ... 당신에 기본값을 넣었습니다.

+0

내가 <섹션 이름 = "ReportEngineConfig"유형 = "Optima.ReportEngine에 라인을 설정 한 .ReportEngineConfig, ReportEngine "allowDefinition ="Everywhere "allowLocation ="true "/>ReportEngine은 dll의 이름이지만이 ["value "]는 여전히 null 참조를 가져옵니다. –