2011-02-02 7 views
9

Per qualche motivo sto ottenendo un errore nel tentativo di restituireASP.NET MVC3 HttpStatusCodeResult StatusDescription - argomento Specified era fuori l'intervallo di valori validi

new HttpStatusCodeResult(500, statusDescription);

Nel mio MVC3 app. Si fa saltare in aria con l'errore

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 

Se cambio il mio risultato di tornare new HttpStatusCodeResult(500, "statusDescription");

Sarà poi lavorare bene, c'è qualche tipo di restrizione lunghezza su Stato Descrizione?

risposta

22

Guardando la fonte, or at the documentation, non può contenere più di 512 caratteri.

+4

Tornando a questa risposta anni dopo, mi fa ancora impazzire per quanto sia stupido questo errore. Anche se devono farlo, il fatto che non sia stato un messaggio di errore significativo e accoppiato con esso non si è rivelato troppo veloce per impostare un valore troppo lungo. ಠ_ಠ –

+1

Ho dovuto solo passare attraverso l'intero WebAPI e trovare i posti in cui viene impostato ReasonPhrase e assicurarmi che la lunghezza sia inferiore a 512. Dopo settimane di persone che hanno sconcertato messaggi di errore ambigui nei log. – Beans

Problemi correlati