c# – 无法强制转换为我的自定义ConfigurationSection

c# – 无法强制转换为我的自定义ConfigurationSection,第1张

概述我正在尝试读取这样的配置文件: var dllPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly. GetExecutingAssembly().GetName().CodeBase);dllPath = dllPath.Replace("file:\\", string.Empty);var confi @H_404_4@ 我正在尝试读取这样的配置文件:

var dllPath =  System.IO.Path.GetDirectoryname(System.Reflection.Assembly.    GetExecutingAssembly().Getname().CodeBase);dllPath = dllPath.Replace("file:\",string.Empty);var configPath = string.Format(@"{0}\..\contentFolders.config",dllPath);var fileMap = new ExeConfigurationfileMap() {ExeConfigfilename = configPath};var config = ConfigurationManager.OpenMappedExeConfiguration(fileMap,ConfigurationUserLevel.None);var contentFolderConfig =     (ContentFolderSettings)config.GetSection("contentFolderConfiguration");

我有在CorpCommon项目中定义的ContentFolderSettings,它继承自ConfigurationSection.以下是contentFolders.config的内容:

<?xml version="1.0" enCoding="utf-8"?><configuration>  <section name="contentFolderConfiguration"    type="Corp.Common.ContentFolderSettings,Corp.Common"    requirePermission="false"/>  <contentFolderConfiguration>    <contentFolders>      <contentFolder key="ImagesFolder" path="content\images"/>      <contentFolder key="CSSFolder" path="content\CSS"/>      ...    </contentFolders>  </contentFolderConfiguration></configuration>

但调用config.GetSection()的行正在抛出InvalIDCastException:

Unable to cast object of type 'System.Configuration.DefaultSection' to type 'Corp.Common.ContentFolderSettings'.
@H_404_4@解决方法 标签丢失了

在我的情况下是这样的:

<configSections>

所以你只需添加标签

@H_404_4@ @H_404_4@ @H_404_4@ @H_404_4@ 总结

以上是内存溢出为你收集整理的c# – 无法强制转换为我的自定义ConfigurationSection全部内容,希望文章能够帮你解决c# – 无法强制转换为我的自定义ConfigurationSection所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1217460.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存