2017-06-30 4 views
0

私のApp.configにカスタムタグを作成するために、MSDNの例の手紙に(ほぼ)従っています( https://msdn.microsoft.com/en-us/library/2tw134k3.aspxApp.configのカスタムタグ - 私のConfigurationSectionクラスの型が認識されない

An unhandled exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.configuration.dll

Additional information: An error occurred creating the configuration section handler for MyServiceGroup/ServiceUpdater: Could not load type 'MyNamespace.ServiceUpdaterSection' from assembly 'System.configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f33d50a4a'.

と(私はApp.configファイルからカスタム情報を利用しようとすると、私のコンソールアプリケーションからメインの内側に)エラーがこの行にトリガーされます。:このエラーを取得しています

MyNamespace.ServiceUpdaterSection serviceUpdaterSection = 
(ServiceUpdaterSection)ConfigurationManager.GetSection("MyServiceGroup/ServiceUpdater"); 

エラーメッセージから、私は徹底的に読むことができますこれはMyNamespace.ServiceUpdaterSectionをSystem.Configuration内に配置しようとしているからです。これとは逆に、MyNamespace内にこのクラス(ServiceUpdaterSection)が完全修飾名を指定しているはずです。ここで

は私のApp.configファイルがどのように見えるかです:

<configSections> 
    <sectionGroup name="MyServiceGroup"> 
     <section name="ServiceUpdater" type="MyNamespace.ServiceUpdaterSection"/> 
    </sectionGroup> 
    </configSections> 

、以下のApp.config内のさらに私が持っている:

<MyServiceGroup> 
    <ServiceUpdater> 
     <licenseKey id="blablabla"/> 
    </ServiceUpdater>  
ServiceUpdaterSectionクラスについては

が、それはように見えます次の:

namespace MyNamespace 
{ 
    public class LicenseKeyElement : ConfigurationElement 
    { 
     [ConfigurationProperty("id")] 
     public string Id 
     { 
      get 
      { 
       return (string)this["id"]; 
      } 
      set 
      { 
       this["id"] = value; 
      } 
     } 
    } 
    public class ServiceUpdaterSection : ConfigurationSection 
    { 
     [ConfigurationProperty("licenseKey")] 
     public LicenseKeyElement LicenseKey 
     { 
      get 
      { 
       return (LicenseKeyElement)this["licenseKey"]; 
      } 
      set 
      { 
       this["licenseKey"] = value; 
      } 
     } 
    } 

} 

あなたの考えはどうですか?

ありがとうございます。

答えて

0

エラーがここにあった:

されている必要があります
<section name="ServiceUpdater" type="MyNamespace.ServiceUpdaterSection"/> 

:他の誰かが同じ問題に遭遇した場合には

<section name="ServiceUpdater" type="MyNamespace.ServiceUpdaterSection, MyNamespace"/> 

はそれを残すだろう。

関連する問題