【问题标题】:PayPal .NET SDK - new Payment() - throws NullReference exceptionPayPal .NET SDK - new Payment() - 引发 NullReference 异常
【发布时间】:2016-12-11 18:04:40
【问题描述】:

我正在尝试通过他们的 .NET SDK 实现 PayPal(C#) 我正在使用 ASP.NET(Web 窗体)。 每当我尝试创建(仅通过构造函数)一个新的 Payment 对象时,我都会得到一个 NullReferenceException,其中绝对没有细节......

这是一个例外:

System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=<SolutionName>
StackTrace:
   at <SolutionName>.Classes.MFPal.Checkout(List`1 cartItems) in C:\<SolutionName>\<FolderName>\Classes\MFPal.cs:line 46
   at <SolutionName>.Pages.Private.ShoppingCart.btnPPCheckout_Click(Object sender, EventArgs e) in C:\<SolutionName>\<FolderName>\Pages\Private\ShoppingCart.aspx.cs:line 164
   at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
   at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException: 
顺便说一下,

InnerExceptionnull

我已经将代码解耦到最低限度,我首先使用填充的 ItemList 进行了测试,现在我只使用了一个空的。现在我也对每个价格使用“0”,但我的第一次测试是用正确的数字进行的。一开始我用的很简单;

Payment.Create(apiContext, new Payment() { ... });

但我无法识别 NullReference,所以现在代码如下所示:

        var apiContext = new APIContext(Config.PayPalAccessToken);
        apiContext.Config = ConfigManager.Instance.GetProperties();
        // ONLY ADDED FOR MORE TESTING.
        apiContext.HTTPHeaders = new Dictionary<string, string>();

        // NULLREF ON THE NEXT LINE
        Payment pym = new Payment() {
            intent = "sale",
            redirect_urls = {
                return_url = "http://<DomainName>/home",
                cancel_url = "http://<DomainName>/home"
            },
            payer = { payment_method = "paypal" },
            transactions = new List<Transaction>() {
                new Transaction() {
                    amount = {
                        currency = "USD",
                        total = "0",
                        details = new Details() {
                            tax = "0",
                            shipping = "0",
                            subtotal = "0"
                        }
                    },
                    item_list = new ItemList() { items = new List<Item>() },
                    description = "asd",
                    invoice_number = "1111111"
                }
            }
        };

有人遇到过类似的问题吗?我错过了什么吗?可能需要的财产?当我调试时,我找不到任何空值。

提前谢谢你!

【问题讨论】:

    标签: c# asp.net paypal paypal-sandbox paypal-rest-sdk


    【解决方案1】:

    我找到了问题。逐行检查,直到我意识到。 我忘记了(Visual Studio 喜欢这个想法):

    new Amount() {...}
    

    构造函数从行:

    amount = {...}
    

    对于看似毫无意义的帖子,我深表歉意。也许有人最终会犯同样的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多