1

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.

Muhammad Usman Bashir
  • 1,441
  • 2
  • 14
  • 43
Kush
  • 196
  • 1
  • 2
  • 13
  • possible duplicate of [What is a NullReferenceException in .NET?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-in-net) –  Dec 04 '12 at 11:49
  • Surely requestId or isPinned is null, evaluate them both and trap some errors! – Paul Zahra Dec 04 '12 at 11:51

4 Answers4

4

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • And it's even simpler if you put the parsing code on separate lines also: int ID = Int32.Parse(requestId); And for even more robustness, you could use TryParse and automatically handle errors. – Steve Wellens Dec 04 '12 at 11:53
  • @SteveWellens: Well, if the problem is that either `requestId` or `isPinned` is null, that should be clear before the parse calls. – Jon Skeet Dec 04 '12 at 11:59
  • @JonSkeet: That's why I suggested TryParse....it handles null values as well as invalid string values. – Steve Wellens Dec 04 '12 at 12:08
  • 1
    @SteveWellens: `TryParse` is only appropriate when it's *expected* to be potentially invalid though. It sounds like the OP really expects it to be valid by now, and an exception is an entirely reasonable response. It's unclear. – Jon Skeet Dec 04 '12 at 12:10
2

It is likely that either context.Request.QueryString["requestId"] or context.Request.QueryString["isPinned"] is not returning a valid string value. Check that both values are passed in the query string with the proper IDs, those being of course requestId and isPinned.

Levi Botelho
  • 24,626
  • 5
  • 61
  • 96
  • Okay solved when passing the values to the handler i inserted it as "PinRequest.ashx?="+requestId+isPinned" Which gave me the result 2True So i realised the hiccup was with not including the string names "PinRequest.ashx?requestId=" + this._requestId + "&isPinned=" + this._isPinned Thanks for you help guys LeviBotelho Thank you made me check something i was missing out when checking as its javascript. – Kush Dec 04 '12 at 12:19
1

Okay solved when passing the values to the handler i inserted it as

"PinRequest.ashx?="+requestId+isPinned"

Which gave me the result 2True

So i realised the hiccup was with not including the string names

"PinRequest.ashx?requestId=" + this._requestId + "&isPinned=" + this._isPinned

Thanks for you help guys

LeviBotelho Thank you made me check something i was missing out when checking as its javascript

Kush
  • 196
  • 1
  • 2
  • 13
0

experienced the error while using Int32.Parse(myString) to convert string to int and afterwards assign the value to an object's attribute. Using another method for converting(Convert.ToInt32(myString)) string to int worked for me.