17

For some reason I'm getting an error trying to return

new HttpStatusCodeResult(500, statusDescription);

In my MVC3 app. It blows up with the error

Specified argument was out of the range of valid values.
Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: value

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: value]
   System.Web.HttpResponse.set_StatusDescription(String value) +4877926
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +785441
   System.Web.Mvc.Controller.ExecuteCore() +159
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.372 

If I change my result to return new HttpStatusCodeResult(500, "statusDescription");

It will then work fine, is there some kind of length restriction on Status Description?

1 Answer 1

37

Looking at the source, or at the documentation, it cannot be more than 512 characters.

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

3 Comments

Coming back to this answer years later, it still makes me mad at how stupid this error is. Even if they have to do it, the fact it was not a meaningful error message and coupled with it not failing fast for setting too long of a value. ಠ_ಠ
I just had to go through the entire WebAPI and find places where ReasonPhrase is being set and make sure length is less than 512. After weeks of people puzzling over ambiguous error messages in the logs.
@Beans That's exactly what happened to me with ReasonPhrase. Thank you so much. God bless you abundently.

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.