none
Unhandled task exceptions RRS feed

  • Question

  • I'm seeing the following exceptions being thrown and am unsure how to fix the underlying problem. They usually come in large quantities at once and am unable to correlate against a request. Looks like a bug in ASP.NET somewhere.

    System.Exception: Unhandled Task Error ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
    at System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)
    at System.Threading.Tasks.Task.Execute()
    --- End of inner exception stack trace ---

    System.Exception: Unhandled Task Error ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
    at System.Web.HttpApplication.ResumeStepsFromThreadPoolThread(Exception error)
    at System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)
    at System.Threading.Tasks.Task.Execute()
    --- End of inner exception stack trace ---

    System.Exception: Unhandled Task Error ---> System.NullReferenceException: Object reference not set to an instance of an object.
    at System.Web.HttpApplication.get_CurrentModuleContainer()
    at System.Web.HttpApplication.PipelineStepManager.ResumeSteps(Exception error)
    at System.Web.HttpApplication.ResumeStepsFromThreadPoolThread(Exception error)
    at System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)
    at System.Threading.Tasks.Task.Execute()
    --- End of inner exception stack trace ---
    Wednesday, December 9, 2015 8:34 PM

Answers

  • NullReferenceException means something is null when it should not be.

    When it occurs in CallHandlerExecutionStep, it usually mean it cannot successfully map a controller for handling the request.

    If it occurs in your testing machine, it'd be handy to fire up Fiddler to see which HTTP request is generating exceptions and find out what is wrong with the parameters.

    I'll add that for some reason, in my recently created MVC projects I almost never use an Action method with parameters defined, and do parameter parsing and call overloads myself in those generic one. Maybe I can count as doing_it_wrong, but at least it's easier to debug routing problem this way, and I don't need extra handling just because some code generates decimal value with thousand seperator (Yup, it'll choke the routing engine if you don't override the BindModel method with code that do extra handling ).

    Thursday, December 10, 2015 1:48 AM
    Answerer

All replies

  • NullReferenceException means something is null when it should not be.

    When it occurs in CallHandlerExecutionStep, it usually mean it cannot successfully map a controller for handling the request.

    If it occurs in your testing machine, it'd be handy to fire up Fiddler to see which HTTP request is generating exceptions and find out what is wrong with the parameters.

    I'll add that for some reason, in my recently created MVC projects I almost never use an Action method with parameters defined, and do parameter parsing and call overloads myself in those generic one. Maybe I can count as doing_it_wrong, but at least it's easier to debug routing problem this way, and I don't need extra handling just because some code generates decimal value with thousand seperator (Yup, it'll choke the routing engine if you don't override the BindModel method with code that do extra handling ).

    Thursday, December 10, 2015 1:48 AM
    Answerer
  • I'm attempting to reproduce the issue locally. Only happens on my cloud machines. I'll investigate further, but I suspect it has to do with something related to signalR.
    Thursday, December 10, 2015 6:18 PM
  • It makes sense.

    If your Action method expects a parameter but there is a problem in SignalR which prevent it from correctly passing the parameter, it'll result in NullReferenceException when determine correct handler to execute.

    Friday, December 11, 2015 1:49 AM
    Answerer
  • Thanks for the reply. Could you give me an example. I'm not sure I fully understand what you mean.

    Thanks again!

    Saturday, December 12, 2015 5:05 AM
  • Say if you have Action method in Controller1 declared as:

    public Action Method1(int Index)
    {
       // do something here...
    }

    If you try to call it with Index passed as null, exception will be thrown  since int cannot hold null value. Now if Index comes from a DOM control dynamically created via javascript on difference script tag, if the script that creates it is broken, the control will not be created, and $("#some_control").val() would just return null. And the submitting code on the other script block can still success. hence the exception you received.

    Sunday, December 13, 2015 9:35 AM
    Answerer