[英]Custom ConfigurationElementCollection Throw TargetInvocationException
I'm trying to make a Custom ConfigurationSection
with ConfigurationElementCollection
.我试图做一个自定义ConfigurationSection
与ConfigurationElementCollection
。 But when i use it throw a ConfigurationErrorsException
with 2 detail exception TargetInvocationException
And MissingMethodException
但是当我使用它时会抛出一个ConfigurationErrorsException
和 2 个细节异常TargetInvocationException
和MissingMethodException
I console some message in the Constructor, result is just "new AssembySettingSection".我在构造函数中安慰一些消息,结果只是“新的 AssembySettingSection”。 Exception throw at AssembySettingSection base["settings"].在 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>
Section Code(Post others when need)部分代码(需要时发布其他人)
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
}
}
}
Sorry, I used the wrong element type in the problem.抱歉,我在问题中使用了错误的元素类型。 Anyway, answering this for other users.无论如何,为其他用户回答这个问题。
The problem is fixed.问题已解决。
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;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.