gpt4 book ai didi

c# - PayPal .NET SDK - new Payment() - 抛出 NullReference 异常

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:25 24 4
gpt4 key购买 nike

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

异常(exception)情况:

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"
}
}
};

有人遇到过类似的问题吗?我错过了什么吗?也许是需要的属性(property)?当我调试时,我找不到任何 null。

提前致谢!

最佳答案

我发现了问题。逐行检查直到我意识到了。我忘了(Visual Studio 喜欢这个想法)遗漏了:

new Amount() {...}

行中的构造函数:

amount = {...}

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

关于c# - PayPal .NET SDK - new Payment() - 抛出 NullReference 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38787269/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com