无法从您的配置中加载“paypal”部分

Posted

技术标签:

【中文标题】无法从您的配置中加载“paypal”部分【英文标题】:Unable to load 'paypal' section from your config 【发布时间】:2015-08-12 14:46:57 【问题描述】:

我在使用 .NET 的 PayPal SDK 时遇到问题。我已经在 Web.config 中填写了我的设置,但是当我尝试使用 PayPal SDK 的 ConfigManager 来获取这些设置时,它会出现以下错误:

Unable to load 'paypal' section from *.config: An error occurred creating the configuration section handler for paypal: Exception has been thrown by the target of an invocation.

我希望有人以前可能遇到过这个问题,或者知道如何帮助我。

我也尝试使用 ConfigurationManager.GetSection("paypal") 手动加载 Web.config 设置,但也没有成功。

先谢谢了,希望你能帮助我!

我的 Web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <configSections>
    <section name="paypal" type="PayPal.SDKConfigHandler, PayPal" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <paypal>
    <settings>
      <add name="mode" value="sandbox"/>
      <add name="connectionTimeout" value="360000"/>
      <add name="requestRetries" value="1"/>
      <add name="clientId" value="CENSORED"/>
      <add name="clientSecret" value="CENSORED" />
    </settings>
  </paypal>

  <log4net>
    <appender name="FileAppender" type="log4net.Appender.FileAppender">
      <file value="myproject.log" />
      <appendToFile value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date 
        [%thread] %-5level %logger [%propertyNDC] %message%newline"/>
      </layout>
    </appender>
    <root>
      <level value="DEBUG" />
      <appender-ref ref="FileAppender" />
    </root>
  </log4net>

  <appSettings>
    <add key="PayPalLogger" value="PayPal.Log.Log4netLogger" />
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusivejavascriptEnabled" value="true" />
    <add key="noReplyPassword" value="hsG3Coj53U" />
    <add key="systemMailPassword" value="F3cLq4gEb5" />
  </appSettings>
  <system.web>
    <trust level="Full" />
    <compilation targetFramework="4.5" debug="true" />
    <httpRuntime targetFramework="4.5" />
    <sessionState mode="InProc" timeout="120" />
    <customErrors mode="Off" />
  </system.web>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Autodiscover XML to php" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*autodiscover.xml" />
          <action type="Rewrite" url="R:1autodiscover.php" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="mysql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.9.6.0" newVersion="6.9.6.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <add name="Entities" providerName="MySql.Data.MySqlClient" connectionString="server=myproject.com;       port=3306;database=myproject;uid=myproject;password=CENSORED;" />
  </connectionStrings>
  <entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices,          MySql.Data.Entity.EF6" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>
</configuration>

【问题讨论】:

您是否偶然安装了 .NET 4.6 RC?我们正在跟踪这个问题over on GitHub。 看起来我有 .NET 4.6,是的。我将重新安装它,然后改用 .NET 4.5.1 重试,谢谢! 感谢您的帮助,它解决了我的问题! 【参考方案1】:

按照 Jason Z 的建议卸载 .NET Framework 4.6 RC,解决了我的问题。

我确信在 PayPal SDK 的较新版本中,它可以与 .NET 4.6 一起使用,但不幸的是,目前还不能。

在安装 PayPal SDK 1.4.2 而不是 1.4.3 时,它似乎也可以工作。

【讨论】:

以上是关于无法从您的配置中加载“paypal”部分的主要内容,如果未能解决你的问题,请参考以下文章

spring - @ContextConfiguration 无法在 src/test/resources 中加载配置文件

如何在Spring容器中加载自定义的配置文件

混合模式程序集是针对版本X构建的,如果没有其他配置信息,则无法在运行时的版本Y中加载

无法在沙盒环境中加载“我的销售工具”

无法在 cshtml 中加载 ReportViewerForMvc 参考

无法在捆绑包 ImageViewCell 中加载 NIB