alexbeletsky / elmah-mvc

Painless integration of ELMAH into ASP.NET MVC application
http://nuget.org/packages/Elmah.MVC
Apache License 2.0
266 stars 61 forks source link

Unexplained NullReferenceException #57

Closed JacobIU closed 9 years ago

JacobIU commented 9 years ago

Good afternoon,

I've recently added the elmah-mvc solution to a project and it works perfectly in iisexpress in local development. However, when deployed to the web server, it throws this NullReferenceException. I've browsed the code, but without a line number and no way to reproduce it locally, I don't have any idea about how to narrow it down any further. There are other applications on this IIS instance that use Elmah successfully, so I don't suspect a server problem.

System.NullReferenceException: Object reference not set to an instance of an object. 
  at Elmah.Mvc.ElmahResult.ExecuteResult(ControllerContext context) 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass1e.<>c__DisplayClass28.<BeginInvokeAction>b__19() 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass1e.<BeginInvokeAction>b__1b(IAsyncResult asyncResult) 
  at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) 
  at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() 
  at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) 
  at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) 
  at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() 
  at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) 
  at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) 
  at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) 
  at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() 
  at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) 
  at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) 
  at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(IAsyncResult asyncResult, ProcessRequestState innerState) 
  at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) 
  at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End() 
  at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) 
  at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) 
  at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
  at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I'm really at a loss. I'm happy to help troubleshoot, but I'm not even clear what else to try.

alexbeletsky commented 9 years ago

Hi @JacobIU, I have no idea what's going wrong (the primary reason, I don't work with .NET for last 3 years) - but I would suggest you clone that repo, build a debug version of assembly and rebuild your project against it. You will get valuable insights and maybe will upload PR with fix.

JacobIU commented 9 years ago

So, some poking around and I think I understand what is at play. If you don't have

  <elmah>
    <security allowRemoteAccess="true" />
  </elmah>

defined, then elmah cannot be accessed remotely. Apparently, one of the side effects of this is the NullReferenceException. So it's not the cause, it's a symptom. If you'd like, I'll make a pull request and update the readme.

JacobIU commented 9 years ago

False alarm. I don't think that's it. I need to do some more troubleshooting.

JacobIU commented 9 years ago

Okay, sorry, I think I can now confirm this was the problem. My theory is that the underlying error message from elmah caused ControllerContext to be null, which caused the exception.

issafram commented 9 years ago

Pull Request #64 should fix this. Let me know if you have more issues after the next release.