簡體   English   中英

PayPal .NET SDK-新的Payment()-引發NullReference異常

[英]PayPal .NET SDK - new Payment() - throws NullReference exception

我正在嘗試通過他們的.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"
                }
            }
        };

是否有人遇到類似的問題? 我想念什么嗎? 可能需要的屬性? 調試時,找不到任何null。

先感謝您!

我發現了問題。 逐行瀏覽直到知道。 我忘記了(Visual Studio很喜歡這個主意)就忽略了:

new Amount() {...}

從行的構造函數:

amount = {...}

很抱歉,我發布的帖子似乎毫無意義。 也許有人最終會犯同樣的錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM