Value cannot be null. Parameter name: String

Kush picture Kush · Dec 4, 2012 · Viewed 27.5k times · Source

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.

Answer

Jon Skeet picture Jon Skeet · Dec 4, 2012

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.