2
votes

All of my controller actions are rendering fine except for one.

I have found other solutions that pertain to IIS express, however this is running on server 2012.

Here is the controller action:

public ActionResult Index()
    {

        try
        {
            var viewModels = GetHostInfoViewModelList();
            return View(viewModels);
        }
        catch (Exception ex)
        {
            ex.ReportError();
            return new HttpStatusCodeResult(404,$"{ex.Message}|{ex.InnerException}");

        }

    }

Here is GetHostInfoViewModelList:

  public IEnumerable<ViewModelHostInfo> GetHostInfoViewModelList()
    {
        using (var db = new WINCMUEntities())
        {
            try
            {
                //join host info with sleep status
                var sleepRecords = db.SleepTrackings.ToList();
                var hostInfo = db.WINCMU_HostInfo.ToList();
                var viewModels = new List<ViewModelHostInfo>();
                hostInfo.ForEach(x =>
                {
                    viewModels.Add(new ViewModelHostInfo()
                    {
                        HostName = x.HostName ?? "Not Found",
                        Id = x.ID,
                        newsystem = x.newsystem,
                        Zone = x.Zone ?? "Not Found",
                        IsSleeping = sleepRecords.FirstOrDefault(s => s.HostName.ToLower() == x.HostName.ToLower())
                                         ?.IsCurrentlySleeping ?? false,
                        IP_address = x.IP_address ?? "Not Found",
                        ReportingArea = x.ReportingArea ?? "Not Found",
                        agent_active = x.agent_active,
                        date_added = x.date_added,
                        is_agent = x.is_agent
                    });
                });

                return viewModels;
            }
            catch (Exception ex)
            {
                ex.ReportError();
                throw;
                //return new List<ViewModelHostInfo>();
            }
        }
    }

Here is the complete error text:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: value] System.Web.HttpResponse.set_StatusDescription(String value) +4538824 System.Web.Mvc.HttpStatusCodeResult.ExecuteResult(ControllerContext context) +109 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +88 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +775 System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +81 System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult) +188 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38 System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +26 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +68 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +52 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +39 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38 System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +40 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +68 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +602 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128

Error Screenshot

2
What is the source code of GetHostInfoViewModelList()? Your problem might be there - Rui Jarimba
Have you tried stepping through your code and see where exactly it's falling over? - Izzy
Thank you Rui! That method had the throw keyword in it which was breaking everything. - Jake Steffen

2 Answers

1
votes

The error message states that is while setting the response status that the exception occurs:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: value] System.Web.HttpResponse.set_StatusDescription(String value) +4538824

Your code does not set the standard description for a 404 status result:

return new HttpStatusCodeResult(404,$"{ex.Message}|{ex.InnerException}");

Change this to:

return new HttpStatusCodeResult(404,"Not Found");

You can omit the description, but if you set it, it must match the status code.

0
votes

This was self inflicted.

GetHostInfoViewModelList was throwing on the exception.