我正试图通过他们的.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>ClassesMFPal.cs:line 46 at <SolutionName>.Pages.Private.ShoppingCart.btnPPCheckout_Click(Object sender, EventArgs e) in C:<SolutionName><FolderName>PagesPrivateShoppingCart.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:
顺便说一句,InnerException为null。
我已经将代码解耦到最低限度,我首先用一个填充的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"
}
}
};
有人遇到类似的问题吗?我是不是错过了什么?也许是一处需要的房产?调试时,找不到任何null。
提前谢谢!
我发现了问题一行一行地读,直到我意识到。我忘了(Visual Studio也很喜欢这个想法(要省略:
new Amount() {...}
来自该行的构造函数:
amount = {...}
我对这篇看似毫无意义的帖子感到抱歉。也许有人最终也会犯同样的错误。