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.

2
  • possible duplicate of What is a NullReferenceException in .NET? Commented Dec 4, 2012 at 11:49
  • Surely requestId or isPinned is null, evaluate them both and trap some errors! Commented Dec 4, 2012 at 11:51

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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.
@SteveWellens: Well, if the problem is that either requestId or isPinned is null, that should be clear before the parse calls.
@JonSkeet: That's why I suggested TryParse....it handles null values as well as invalid string values.
@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.
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.

1 Comment

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.
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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.