c# - 获取堆栈跟踪错误并且不明白为什么

标签 c# .net asp.net-mvc paypal paypal-ipn

我正在尝试使用 PayPal IPN 方法。所以我想因为我正在做 asp.net mvc 我可以像这样在我的 Controller 中制作一个方法 View

public void IPN()
{
  // IPN code
}

所以我在本地主机上尝试了这一切,制作了我自己的表格来发布一些 IPN 变量内容,并且效果很好。我将它上传到我的服务器并使用了来自 paypal 的 IPN 模拟器,它一直返回服务器 500 错误。

所以我把所有的代码都拿出来了,基本上你看到的只是我 Controller 中的一个空方法。所以我再次尝试了 teh 模拟器,它再次失败并出现服务器 500 错误。

所以我去输入了我的 url 到那个 Controller 方法,我得到了这个堆栈跟踪。

[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()

这样做可以帮助您找出代码中发生故障的位置。

关于c# - 获取堆栈跟踪错误并且不明白为什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1591090/

相关文章:

C# 和 Selenium : selectByText using a dropdownlist

php - PHP 脚本可以在收到所有 POST 数据之前启动吗?

.net - 在多个应用程序中生成文档

asp.net-mvc - Azure Active Directory 和单点登录的访问 token

css - 在 ASP.NET MVC 的 View 中显示格式化的 JSON

c# - MVC 4 : How to make DropDownListFor return 0 as optionLabel value?

c# - silverlight工具包中的AutoCompleteBox for windows phone错误显示

c# - Asp.Net MVC 路由不接受 & 在路由中

c# - 为什么 !0 是 Microsoft 中间语言 (MSIL) 中的一种类型?

javascript - 获取表中的行数