
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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)