c# - 很难理解 Stack Trace

标签 c# .net asp.net-mvc

我很难重现场景或阅读我今天在日志中遇到的以下错误。通常堆栈跟踪会指向文件和行号等,但正如您在下面看到的那样,它只显示 nullreference没有给我具体位置的异常..如果你能帮助我阅读这个并找出正在发生的事情,我将不胜感激..

System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'. ---> System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object.
  at ASP.views_reservation_checkout_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer)
  at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
  at ASP.content_kismetvacation_views_shared_site_master.__RenderBodyContent(HtmlTextWriter __w, Control parameterContainer)
  at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
  at ASP.content_kismetvacation_views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer)
  at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
  at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
  at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  at System.Web.UI.Page.HandleError(Exception e)
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  at System.Web.UI.Page.ProcessRequest()
  at System.Web.UI.Page.ProcessRequest(HttpContext context)
  at System.Web.Mvc.ViewPage.ProcessRequest(HttpContext context)
  at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.<>c__DisplayClass4.<Wrap>b__3()
  at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1 func)
  at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
  at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)
  at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage)
  at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)
  at System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext)
  at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
  at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<InvokeActionResultWithFilters>b__11()
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
  at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
  at System.Web.Mvc.Controller.ExecuteCore()
  at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__4()
  at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
  at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object.
  at ASP.views_reservation_checkout_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer)
  at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
  at ASP.content_kismetvacation_views_shared_site_master.__RenderBodyContent(HtmlTextWriter __w, Control parameterContainer)
  at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
  at ASP.content_kismetvacation_views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer)
  at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
  at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
  at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  at System.Web.UI.Page.HandleError(Exception e)
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  at System.Web.UI.Page.ProcessRequest()
  at System.Web.UI.Page.ProcessRequest(HttpContext context)
  at System.Web.Mvc.ViewPage.ProcessRequest(HttpContext context)
  at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.<>c__DisplayClass4.<Wrap>b__3()
  at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func`1 func)
  at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)

最佳答案

堆栈跟踪的顶行来自最深点(发生错误的位置),下面几行是从堆栈中冒泡备份的。

我删除了 System.* 条目(它进入 .NET Framework 的位置),剩下的大部分是您的页面和类。它使它更具可读性,也许更易于管理......

System.Web.HttpException (0x80004005): Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'. ---> System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object.
  at ASP.views_reservation_checkout_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer)
  at ASP.content_kismetvacation_views_shared_site_master.__RenderBodyContent(HtmlTextWriter __w, Control parameterContainer)
  at ASP.content_kismetvacation_views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer)

System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object.
  at ASP.views_reservation_checkout_aspx.__RenderContent2(HtmlTextWriter __w, Control parameterContainer)
  at ASP.content_kismetvacation_views_shared_site_master.__RenderBodyContent(HtmlTextWriter __w, Control parameterContainer)
  at ASP.content_kismetvacation_views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer)

我在那里看到了您的内容页面:*views_reservation_checkout_aspx*
和一个 View :*content_kismetvacation_views_shared_site_master*

最深处显示名为 ASP.views_reservation_checkout_aspx 的网页 (ASP/views/reservation/checkout.aspx ?) 因此您应该将调试工作集中在其中的对象和控件上。

在该页面中尝试的事情:

  • 在 Visual Studio 中设置断点
    • 并逐行执行代码,
    • 一路检查事物的实例是否为 null
    • 在为空的实例上查找成员调用(例如方法或属性)。
  • 修复并重复

关于c# - 很难理解 Stack Trace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5891508/

相关文章:

c# - 强制在声明中使用接口(interface)而不是具体实现 (.NET)

c# - 在 switch 中减去一个 public in

c# - 使用 Json.Net 从流反序列化时如何设置自定义日期格式

c# - LINQ .Where 查询执行时间超过 5 分钟

javascript - 有没有办法在部分 View 中获取 ajax 调用的 Controller 路径?

c# - 关于 Enum 和 DataAnnotation

c# - 使用 Array.CopyTo 复制元素是否正确,还是应该始终使用 for 循环?

c# - 我能否使 NumericUpDown 控件的最大值不受限制,而不是在其 Maximum 属性中指定一个值?

asp.net-mvc - Application_AuthenticateRequest 上的 ASP.NET MVC 重定向困境

c# - 如何在模型和 View 模型中使用 "DRY up"C# 属性?