自定义 ConfigurationElementCollection 抛出 TargetInvocationException

Custom ConfigurationElementCollection Throw TargetInvocationException

我正在尝试使用 ConfigurationElementCollection 制作自定义 ConfigurationSection。 但是当我使用它时抛出一个 ConfigurationErrorsException with 2 detail exceptionTargetInvocationException And MissingMethodException

我在 Constructor 中控制了一些消息,结果只是 "new AssembySettingSection"。 在 AssembySettingSection base["settings"].

处抛出异常

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="AssembySetting" type="IngoWinService.AssembySettingSection, IngoWinService"/>
  </configSections>
  <AssembySetting>
    <settings>
      <add name="IngoWinService.Haier.Service" assemby="IngoWinService.Haier" />
    </settings>
  </AssembySetting>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
</configuration>

段代码(Post其他需要时)

public class AssembySettingSection : ConfigurationSection
{
    public AssembySettingSection()
    {
        System.Console.WriteLine("new AssembySettingSection");
    }
    [ConfigurationProperty("settings", IsDefaultCollection = false)]
    [ConfigurationCollection(typeof(AssembySettingCollection))]
    public ConfigurationElementCollection Settings
    {
        get
        {
            return base["settings"] as AssembySettingCollection;//Throw Exception
        }
    }

}

抱歉,我在问题中使用了错误的元素类型。无论如何,为其他用户回答这个问题。

问题已解决。

public class AssembySettingSection : ConfigurationSection
{
    public AssembySettingSection()
    {
        System.Console.WriteLine("new AssembySettingSection");
    }
    [ConfigurationProperty("settings", IsDefaultCollection = false)]
    [ConfigurationCollection(typeof(AssembySettingElement))]//Changed AssembySettingCollection to AssembySettingElement
    public AssembySettingCollection Settings
    {
        get
        {
            return base["settings"] as AssembySettingCollection;
        }
    }

}