Top level category model mismatch error

Vote:
 

Hey All,

We're using EpiServer 9.8 and getting a strange error when loading our top-level category page.  What's weird about it is if you refresh the page, it works just fine and the error cannot be reproduced again until you refresh the app pool in IIS.  The error we're getting is:

"The routed data is of type 'CMS.Models.Commerce.Catalog.CategoryContentType' and the binding context data 'currentPage' is of type 'CMS.Models.Commerce.Catalog.CategoryContentType', neither of which matches the requested type 'CMS.Models.Pages.SitePageData'."

Stack trace:

[TypeMismatchException: The routed data is of type 'CMS.Models.Commerce.Catalog.CategoryContentType' and the binding context data 'currentPage' is of type 'CMS.Models.Commerce.Catalog.CategoryContentType', neither of which matches the requested type 'CMS.Models.Pages.SitePageData'.]
EPiServer.Web.Mvc.ContentDataModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +769
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +296
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +105
System.Web.Mvc.Async.<>c__DisplayClass25.b__1e(AsyncCallback asyncCallback, Object asyncState) +445
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +129
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +302
System.Web.Mvc.<>c__DisplayClass1d.b__17(AsyncCallback asyncCallback, Object asyncState) +30
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +129
System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +338
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +129
System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +316
System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +15
System.Web.Mvc.<>c__DisplayClass8.b__2(AsyncCallback asyncCallback, Object asyncState) +71
System.Web.Mvc.Async.WrappedAsyncResult`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +129
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +251
System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

And here is our code for the controller's ActionResult:

namespace CMS.Controllers.Commerce
{
    public class CategoryController : ContentController
    {
        public ActionResult Index(CategoryContentType currentContent, SitePageData currentPage)
        {
            CommerceCoreRepository CommerceData = new CommerceCoreRepository(Global.DatabaseConnection.EOShared);
            CultureInfo currentCulture = ContentLanguage.PreferredCulture;
            string languageCode = currentCulture.Name;
            ViewBag.CurrentPage = currentPage;
            CategoryModel model = new CategoryModel()
            {
                Breadcrumb = new BreadcrumbModel(currentContent),
                Category = currentContent
            };
            return View("/Views/Commerce/Product/Category/Index.cshtml", model);
        }

}
}


Any insight or experience with this would be greatly appreciated, we're a bit stumped.

Thanks!

John

#174260
Jan 23, 2017 16:09
Vote:
 

Hi,

Do you have any controller which inherits from PageController<SitePageData>?

It seems to me that your Index method matches both CategoryController and the other one. 

#174261
Jan 23, 2017 16:56
Vote:
 

The short answer is no, but what strikes me as odd is that you can go directly to any of the sub-categories and they load up just fine.  It's ONLY throwing an error on top level categories and even then ONLY when the app pool is recycled.  You can refresh the page right then and there and it loads up fine and the error never appears again.  It's very strange.

#174262
Jan 23, 2017 17:15
Vote:
 

Just following up with some more details here, it seems like for whatever reason, when a category at the top level of our site's page is loaded, and only for the first time after IIS or the app pool is restarted, its trying to pass CategoryContentType instead of SitePageData, anyone experience this or something similar before?  

Thanks!

John

#174467
Jan 26, 2017 16:27
Vote:
 

Do you have some custom routing in your code? How are you defining the route for above controller? I suspect currentPage will always be null, even after the first load.

/K

#174615
Jan 31, 2017 22:25
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.