U4-10822 - Modelsbuilder error: Cannot bind source type to model type - but types are exactly the same

Created by Sebastiaan Janssen 11 Jan 2018, 15:16:19 Updated by Sebastiaan Janssen 24 Jan 2018, 13:35:03

Subtask of: U4-9609

Seems that after switching from PureLive mode to Dll mode, sometimes "something" gets left behind from the PureLive mode. This leads to an error that looks like this:

2018-01-09 15:30:18,487 [P8412/D8/T6] ERROR Umbraco.Core.UmbracoApplicationBase - An unhandled exception occurred Umbraco.Web.Mvc.ModelBindingException: Cannot bind source type ArticleViewModel to model type ArticleViewModel. at Umbraco.Web.Mvc.RenderModelBinder.ThrowModelBindingException(Boolean sourceContent, Boolean modelContent, Type sourceType, Type modelType) at Umbraco.Web.Mvc.RenderModelBinder.BindModel(Object source, Type modelType, CultureInfo culture) at Umbraco.Web.Mvc.UmbracoViewPage1.SetViewData(ViewDataDictionary viewData) at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) at Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.b__1c() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.b__1e(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) at System.Web.Mvc.Controller.b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) at System.Web.Mvc.Controller.b__15(IAsyncResult asyncResult, Controller controller) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.b__5(IAsyncResult asyncResult, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

This error usually shows up right after a site has been restarted.

1 Attachments

Comments

Stephan 11 Jan 2018, 15:31:40

Error message ''"Cannot bind source type ArticleViewModel to model type ArticleViewModel"'' does not mention PureLive, meaning that either the source object, of the view model, or both, are not PureLive models. This is a very weird situation that ''may'' happen when switching over from PureLive to Dll, or back. Problem is, we have very little useful infos to troubleshoot. Looking into improving error reporting to better understand what happens.


Stephan 11 Jan 2018, 15:46:59

new Core branch in PR https://github.com/umbraco/Umbraco-CMS/pull/2384 introduces an event that triggers on binding errors, and can be handled by ModelsBuilder for more detailed reporting.

new ModelsBuilder branch temp-u4-10822 (no PR yet) handles the Core event and reports the errors with more details - still work in progress, in some cases we might want to dump the process


Stephan 12 Jan 2018, 12:51:31

Have pushed a commit to Core branch to deal with a breaking change.


Stephan 22 Jan 2018, 14:02:21

have pushed to the ModelsBuilder branch - which depends on the Core branch to work - we're not going to create dumps for now - we're going to see if we see the new error messages in production first

review: rebuild Core with the PR merged, rebuild ModelsBuilder updating Core dependency to the one you've rebuilt, test that it all works

now how are we going to build ModelsBuilder depending on 7.8, for 7.8? should build on a recent beta, and updated soon as 7.8 is released


Sebastiaan Janssen 23 Jan 2018, 15:32:39

Leaving in Review for now, we need to update ModelsBuilder and try if we can make it non-breaking.


Sebastiaan Janssen 23 Jan 2018, 20:32:21

FYI: ModelsBuilder PR: https://github.com/zpqrtbnk/Zbu.ModelsBuilder/pull/162

Tested against 7.7.7 and 7.8.0 "beta010" - that beta version has the required events built into it, so it adds the eventhandler. That all worked well.

Waiting for MB 3.0.9 public release so we can reference it in core.


Sebastiaan Janssen 23 Jan 2018, 20:39:22

FYI: On a version that has the events built in, they add the handler - screenshot.


Sebastiaan Janssen 24 Jan 2018, 13:35:03

All updated now.


Priority: Normal

Type: Bug

State: Fixed

Assignee:

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions:

Due in version: 7.7.10

Sprint: Sprint 77

Story Points: 1

Cycle: 7