U.F. Developer
U.F. Developer

Reputation: 87

custom app.config in c# generates configuration system failed to initialize exception

I checked all the solutions on internet related to configuration system failed to initialize exception but none of them working for me. So I am posting this question.

I am working on PayPal REST API in winform c#. I customized my app.config file. When I rebuild the application It shows the Configuration system failed to initialize

Here is Default app.config code:

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

And Here is my Custom app.config code:

<?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>

EDIT:

I used try catch block to catch the exception, otherwise program does not terminate but working abnormally. My call stack is empty. I used try catch on form load.

Upvotes: 3

Views: 384

Answers (1)

U.F. Developer
U.F. Developer

Reputation: 87

My Problem Solved by putting the <configSection> as the first child element of <configuration>.

It was a rearrange of code.

Here is the new code:

<?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>

Upvotes: 3

Related Questions