簡體   English   中英

越來越跟蹤錯誤,不明白為什么

[英]Getting strack trace error and don't understand why

我正在嘗試做PayPal IPN方法。 所以我想,因為我正在做asp.net mvc,所以我可以像這樣在控制器中創建方法視圖

public void IPN()
{
  // IPN code
}

因此,我在本地主機上以自己的形式嘗試了所有這些操作,以發布一些IPN變量內容,並且效果很好。 我將其上傳到我的服務器上,並使用了來自Paypal的IPN模擬器,它不斷返回服務器500錯誤。

因此,我取出了所有代碼,基本上了解了控制器中只有一個空方法的情況。 因此,我再次嘗試了模擬器,但由於服務器500錯誤而再次失敗。

因此,我實際輸入了該控制器方法的網址,並得到了該堆棧跟蹤。

[NullReferenceException: Object reference not set to an instance of an object.]
   site.com.Controllers.MyTestController.IPN() in MyTestController:2320
   lambda_method(ExecutionScope , ControllerBase , Object[] ) +39
   System.Web.Mvc.<>c__DisplayClass1.<WrapVoidAction>b__0(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +178
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +24
   System.Web.Mvc.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7() +53
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +258
   System.Web.Mvc.<>c__DisplayClassc.<InvokeActionMethodWithFilters>b__9() +20
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +193
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +382
   System.Web.Mvc.Controller.ExecuteCore() +123
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +144
   System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +54
   System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

我不確定MyTestController:2320是否引用2320行(因為它不存在)或什么。

謝謝

右邊的那些數字是已編譯代碼的偏移量,因此它們不會指向任何源代碼行號。

在這種情況下,我要做的是將某種形式的日志記錄到代碼中,以便我可以知道在代碼中的何處引發了異常。 根據對代碼上傳服務器的訪問權限,您可能能夠創建日志文件或事件日志等,並使用Trace語句:

Trace.WriteLine("Controllers.MyTestController.IPN(): Creating object.")

Dim o As New Object

Trace.WriteLine("Controllers.MyTestController.IPN(): Call PayPal web service.")

Call PayPal.GetAccountNumber()

這樣做可以幫助您發現代碼中發生故障的位置。

沒有看到代碼,我們無法確定NullReferenceException發生在哪里。

但是,根據我自己設置IPN的經驗,我認為您很可能引用了空string對象。 例如 :

string foo = Request.Form["bar"];
foo.Trim();
//if the form collection doesn't contain a value for the key "bar" then it'll
//throw a NullReferenceException on foo.Trim()

只要確保您沒有在任何對象上調用任何方法,屬性,而不必確保它們不為null。

暫無
暫無

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

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