Search code examples
c#exceptionhandlerrequest.querystringnul

Value cannot be null. Parameter name: String


Please take a look at the following code. It's in handler.asxh.

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "application/json";
    new RequestManagementFacade().PinRequest(Int32.Parse(context.Request.QueryString["requestId"]), (Boolean.Parse(context.Request.QueryString["isPinned"])));
}

This is showing the following error:

Value cannot be null. Parameter name: String

There is value being passed as I have checked the context request query string, however, the code breaks at this stage.

This handler will connect to the business logic layer.


Solution

  • There is value being passed as i have checke dthe context request query string

    I strongly suspect your diagnostics are incorrect then. Values don't magically go missing - you need to question your assumptions. This is easy to debug through though. I would suggest changing your code to:

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "application/json";
        string requestId = context.Request.QueryString["requestId"];
        string isPinned = context.Request.QueryString["isPinned"];
        var facade = new RequestManagementFacade();
        facade.PinRequest(Int32.Parse(requestId), Boolean.Parse(isPinned));
    }
    

    It's then really simple to step through and find out what's going on.