无法识别的元素“添加”读取 web.config 时出错
当我执行此操作时 ConfigurationManager.GetSection("SectionA/sectionD")
我收到此错误:
无法识别的元素“add”
我想读取本节中的所有“add”元素以创建一个集合。
<configSections>
<sectionGroup name="SectionA">
<sectionGroup name="SectionB">
<section name="sectionC" type="MyProject.SectionC,MyProject" />
<section name="sectionD" type="MyProject.SectionD,MyProject" />
</sectionGroup>
<section name="sectionE" type="MyProject.SectionE,MyProject" />
</sectionGroup>
</configSections>
<SectionA>
<SectionB>
<sectionD>
<add key="PerPage10" value="10" />
<add key="PerPage30" value="30" />
<add key="PerPage60" value="60" />
</sectionD>
<sectionC attribute3="10" />
</SectionB>
<sectionE attribute1="3" attribute2="5" />
</SectionA>
When I do this ConfigurationManager.GetSection("SectionA/sectionD")
I receive this error:
Unrecognized element 'add'
I'd like read all "add" element from this section to create a collection.
<configSections>
<sectionGroup name="SectionA">
<sectionGroup name="SectionB">
<section name="sectionC" type="MyProject.SectionC,MyProject" />
<section name="sectionD" type="MyProject.SectionD,MyProject" />
</sectionGroup>
<section name="sectionE" type="MyProject.SectionE,MyProject" />
</sectionGroup>
</configSections>
<SectionA>
<SectionB>
<sectionD>
<add key="PerPage10" value="10" />
<add key="PerPage30" value="30" />
<add key="PerPage60" value="60" />
</sectionD>
<sectionC attribute3="10" />
</SectionB>
<sectionE attribute1="3" attribute2="5" />
</SectionA>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是配置元素集合代码声明的示例:
所以在 config 中它看起来如下:
Here's an example of configuration element collection code delcaration:
So in config it looks as following: