我正在尝试ConfigurationSection使用ConfigurationElementCollection. 但是当我使用它时会抛出一个ConfigurationErrorsException带有 2 个详细信息的异常TargetInvocationException并且MissingMethodException我在构造函数中安慰一些消息,结果只是“新的 AssembySettingSection”。在 AssembySettingSection base["settings"] 处抛出异常。应用配置<?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 回答
12345678_0001
TA贡献1802条经验 获得超5个赞
抱歉,我在问题中使用了错误的元素类型。无论如何,为其他用户回答这个问题。
问题已解决。
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;
}
}
}
- 1 回答
- 0 关注
- 164 浏览
添加回答
举报
0/150
提交
取消