加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 创建配置节处理程序时发生错误

发布时间:2020-12-16 00:22:52 所属栏目:百科 来源:网络整理
导读:我有一个dot.NET 4.0 Web应用程序,其中定义了自定义部分: configuration configSections section name="registrations" type="System.Configuration.IgnoreSectionHandler,System.Configuration,System,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77
我有一个dot.NET 4.0 Web应用程序,其中定义了自定义部分:

<configuration>
    <configSections>
    <section name="registrations" type="System.Configuration.IgnoreSectionHandler,System.Configuration,System,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089" requirePermission="true" restartOnExternalChanges="true" allowLocation="true"/>
    ....

在web.config文件的末尾我有相应的部分:

....
  <registrations>
    .....
  </registrations>
</configuration>

每次我调用System.Configuration.ConfigurationManager.GetSection(“registrations”);我得到以下异常:

An error occurred creating the configuration section handler for registrations: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047) (C:…web.config line 13)

我也在使用Unity,但不知道这是否与错误有关.

你以前遇到过这个错误吗?我该如何解决?我是否需要用其他东西替换IgnoreSectionHandler?

解决方法

您缺少App.Config中部分的type属性中的命名空间.事实上,你也不需要完整的装配信息.只有命名空间就足够了

更新1

yourcustomconfigclass config =(yourcustomconfigclass)System.Configuration.ConfigurationManager.GetSection(
    "registrations");

并在配置文件中只写

<section name="registrations" type="System.Configuration.IgnoreSectionHandler" requirePermission="true" restartOnExternalChanges="true" allowLocation="true"/>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读