【问题标题】:The type initializer for 'PayPal.Manager.ConfigManager' threw an exception -->Paypal SetExpressCheckout'PayPal.Manager.ConfigManager' 的类型初始值设定项引发异常 -->Paypal SetExpressCheckout
【发布时间】:2012-09-01 04:15:53
【问题描述】:

我在使用 PayPal 的 API 时遇到了一些问题。当我尝试调用 SetExpressCheckout 方法时(并且我相信我添加了与示例中相同的项目/类),我收到以下错误:

The type initializer for 'PayPal.Manager.ConfigManager' threw an exception.

给出的内部异常是:

{"Cannot read config file"}

这让我想到:我的 PayPal API 调用方法在一个程序集中,我有一个 Web 服务,它调用该程序集中的方法来使用 PayPal API。很简单,它的工作原理是这样的:

Web Service ---calls---> Assembly ---calls---> PayPal API

有人知道为什么会这样吗?它真的让我感到困惑,它如何在示例项目中工作,但在我自己的项目中却无法工作。

【问题讨论】:

  • 考虑查看“内部异常”以获取异常的确切类型。
  • 内部异常显示:{"Cannot read config file"} 你们有使用 PayPal SDK 的经验吗?你知道这可能是什么原因造成的吗?
  • 一个想法,我忘了在我的帖子中提到(我现在会改变它)是我在一个程序集中有 PayPal API 调用代码,我正在从网络调用该程序集的方法ASP.NET 项目中的服务。

标签: c# paypal express-checkout


【解决方案1】:

因为它还没有出现任何答案,并且我在 MVC3 .Net 应用程序中实现 PayPal API 时遇到了同样的错误,所以以下对我有用。它直接取自 PayPal API 示例 .Net Project Web.Config:

在您的 Web.Config 文件的顶部(作为第一个子元素)添加如下引用:

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

然后添加 PayPal SDK 配置

<paypal>
  <settings>
    <!-- The URL that the user must be redirected to in order to login and approve some payment actions-->
    <add name="paypalUrl" value="https://www.sandbox.paypal.com/webscr?cmd="/>
    <!-- The API endpoint -->
    <add name="endpoint" value="https://api-3t.sandbox.paypal.com/2.0"/>
    <!-- Connection timeout in milliseconds -->
    <add name="connectionTimeout" value="360000"/>
    <!-- The number of times a request must be retried if the API endpoint is   unresponsive -->
    <add name="requestRetries" value="3"/>
    <add name="binding" value="SOAP"/>
    <add name="IPAddress" value="127.0.0.1"/>
    <!-- 
      API version number. You will not normally have to change this unless you
      have a specific need to work with an older version of the API
     -->
    <add name="APIVersion" value="84.0"/>
  </settings>

  <accounts>
    <!--
      Add API credentials - 3 token or client certificate.
      You can add multiple account credentials here. The SDK will pick the first   account
      unless you specifically request an account in the service wrapper mehod.
    -->
    <account apiUsername="sdk-three_api1.sdk.com" apiPassword="QFZCWN5HZM8VBG7Q"
        apiSignature="A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU"   applicationId="APP-80W284485P519543T"/>
    <!--
    <account apiUsername="enduser_biz_api1.gmail.com" apiPassword="SACH3VA3C29DXGUG"
      apiCertificate="<Absolute path to paypal_cert.p12>" 
             privateKeyPassword="password" applicationId="APP-80W284485P519543T"/>
     -->           
  </accounts>
</paypal>

【讨论】:

  • 我安装了 PayPalMerchantSDK nuget 包,而不是 PayPal_Merchant_SDK 包。我不确定有什么区别,但我不得不更改一行(除了特定于凭证的内容):&lt;section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK" /&gt;。除此之外,它就像一个魅力。谢谢你让我走上正轨。我希望我能批准这个答案。
猜你喜欢
  • 2011-05-22
  • 2012-09-06
  • 2014-01-23
  • 2014-04-10
  • 1970-01-01
  • 1970-01-01
  • 2018-07-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多