自定义ConfigurationElementCollection引发TargetInvocationException

时间:2018-08-15 08:05:14

标签: c# .net-4.0 app-config

我正在尝试使用ConfigurationSection创建自定义ConfigurationElementCollection。 但是当我使用它时,抛出一个ConfigurationErrorsException并带有2个详细信息异常TargetInvocationExceptionMissingMethodException

我在构造函数中控制台了一些消息,结果只是“ 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>

部门代码(在需要时发布其他信息)

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

}

1 个答案:

答案 0 :(得分:0)

很抱歉这个愚蠢的错误。我使用了错误的元素类型。 无论如何,请为某人保留

固定

string agentIdSubQuery =    "AGENT_ID " +
                                 "FROM " +
                                     "KS_DRIFT.V_AGENT_ALLOCATION " +
                                 "WHERE " +
                                     "LENGTH(AGENT_INITIALS) < 5 " +
                                     " AND ROWNUM = 1 " +
                                 " ORDER BY ALLOCATION_START DESC";