如何修复这个奇怪的ConfigurationSection异常

本文关键字:ConfigurationSection 异常 何修复 | 更新日期: 2023-09-27 18:03:41

我的任务是让这个第三方软件在我们的服务器上运行,但我们只能部分访问代码,其余的仅作为预编译库存在。其中一个库抛出了神秘的异常,我不知道为什么。我完全忘记了Visual Studio和c#,这对我来说毫无意义。

我最初得到的是:

未处理的例外:

Unhandled Exception: System。TypeInitializationException:类型GroupsImporter的初始化器。程序抛出了一个异常。——>

System.Configuration。ConfigurationErrorsException:配置系统初始化失败-->

System.Configuration。ConfigurationErrorsException: 承认配置部分ThirdPartyCompany.Framework.Core.Configuration.v1.2。(Y: ' path-to-executable ' GroupsImporter.exe。配置行67)

在System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(布尔ignoreLocal)

System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors (ConfigurationSchemaErrorsschemaErrors)

System.Configuration.ClientConfigurationSystem.EnsureInit(字符串configKey)

——内部异常堆栈跟踪结束——

配置文件如下所示:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <section name="AdWordsApi" type="System.Configuration.DictionarySectionHandler"/>
        <section name="AdWords.Common.Configuration" type="AdWords.Common.Configuration.AdWordsConfiguration, AdWords.Common"/>
    </configSections>
    <appSettings>
        ...
    </appSettings>
    <AdWords.Common.Configuration Budget ="xxx" CPC="xxx" EstoqueMinimo="x">
        ...
    </AdWords.Common.Configuration>
    <AdWordsApi>
        ...
    </AdWordsApi>
    <system.web>
        ...
    </system.web>
    <system.net>
        ...
    </system.net>
    <ThirdPartyCompany.Framework.Core.Configuration.v1.2>
        ...
    </ThirdPartyCompany.Framework.Core.Configuration.v1.2>
</configuration>

反过来,如果我删除它抱怨的部分,我得到这个:

Unhandled Exception: System。TypeInitializationException:类型GroupsImporter的初始化器。程序抛出了一个异常。——>

System.Configuration。ConfigurationException: configuration节ThirdPartyCompany.Framework.Core.Configuration.v1.2不能发现。

在ThirdPartyCompany.Framework.Core.Guard.Against TException(布尔断言,字符串消息)

在ThirdPartyCompany.Framework.Core.Configuration.ConfigurationSection.GetConfiguration ()

在ThirdPartyCompany.Framework.Core.IoCContainerWrapper.Implementation.IoCThirdPartyCompanyContainer.loadRegisterConfiguration ()

//

我不知道如何解决这个问题。我无法访问实现ServiceConfig类的代码或使用配置的代码。关于发生了什么,以及如何解决这个问题,有什么想法吗?

编辑:它应该在公司的服务器上工作,完全按照提供的。

如何修复这个奇怪的ConfigurationSection异常

IIRC,您需要将该部分添加到configSections标记。

就像这个:

<section name="AdWordsApi"

…但你也需要:

<section name="ThirdPartyCompany.Framework.Core.Configuration.v1.2" ...

你必须确保你引用了这些库,或者询问哪个库实现了系统抱怨的"ConfigurtionSection"类。

不能发布答案:是的,你可以添加自定义配置节(不是应用程序键)的唯一方法,据我所知是从ConfigurationSection类继承

我有相同的错误与不同的dll,消息是:
"无法识别的配置节AdWordsApi"

我修复了使用nuget控制台重新安装AdWordsApi引用的问题。

从Nuget Package Manager Console execute:
Install-Package Google.AdWords

它将重新安装包并在app.config

中添加以下代码
  <configSections>
    <section name="AdWordsApi" type="System.Configuration.DictionarySectionHandler" />  
  </configSections>
相关文章:
  • 没有找到相关文章