【问题标题】:custom app.config in c# generates configuration system failed to initialize exceptionc#自定义app.config生成配置系统初始化失败异常
【发布时间】:2017-04-29 11:02:51
【问题描述】:

我检查了互联网上与配置系统相关的所有解决方案未能初始化异常,但没有一个对我有用。 所以我发布了这个问题。

我正在使用 winform c# 处理 PayPal REST API。我自定义了我的 app.config 文件。当我重建应用程序时它显示Configuration system failed to initialize

这是默认 app.config 代码:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
</configuration>

这是我的自定义 app.config 代码:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

  <configSections>
    <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
  </configSections>

<!--PayPal SDK settings-->
  <paypal>
    <settings>
      <add name="mode" value="sandbox" />
      <add name="clientId" value="__CLIENT_ID__" />
      <add name="clientSecret" value="__CLIENT_SECRET__" />
    </settings>
  </paypal>

</configuration>

编辑:

我使用try catch块来捕获异常,否则程序不会终止而是工作异常。我的调用堆栈是空的。我在表单加载时使用了 try catch。

【问题讨论】:

  • 堆栈跟踪怎么样?内部异常是否提供更多信息?
  • 基本上我使用try catch块来捕获异常,否则程序不会终止但工作异常。我的调用堆栈是空的。
  • @PaoloTedesco 我在表单加载时使用了 try catch。

标签: c# winforms paypal app-config


【解决方案1】:

我的问题通过将&lt;configSection&gt; 作为&lt;configuration&gt; 的第一个子元素来解决。

这是对代码的重新排列。

这是新代码:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
  <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
 </configSections>
 <startup>
   <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
 </startup>

 <!--PayPal SDK settings-->
 <paypal>
   <settings>
     <add name="mode" value="sandbox" />
     <add name="clientId" value="__CLIENT_ID__" />
     <add name="clientSecret" value="__CLIENT_SECRET__" />
   </settings>
 </paypal>

</configuration>

【讨论】:

    猜你喜欢
    • 2018-03-23
    • 2014-03-08
    • 2012-04-23
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    相关资源
    最近更新 更多