Quantcast
Channel: CSLA .NET
Viewing all articles
Browse latest Browse all 764

ModelBinder System.MissingMethodException: Cannot create an instance of an interface

$
0
0

This is possbily related to my previous post around odd grid binding behaviour (waiting for approval).

I have an MVC 5 web app and a model with child objects and am binding this in a Kendo grid control.  When attempting to update a child row the model binder appears to be throwing an error, and the call to the update method in the controller never gets fired.

"System.MissingMethodException: Cannot create an instance of an interface".  The key indicator seems to be "MissingMethodException: Cannot create an instance of an interface. Object type 'Csla.Core.IParent"

So it looks like it's failing trying to work out the parent property of the child.  .Net can't spin up an interface - it needs the real concrete class.

Now I don't think this is a CSLA issue, but rather a Kendo grid + Csla binder interaction going on here, and I know grids and binding always throw some fun issues into the mix.  I have set the MVC default model binder to use the Csla version.

Any ideas?  The razor form binds directly to the model - not using the CslaViewModelBase (maybe I can try that).

I can work around this by using custom commands (a.k.a firing my own JavaScript ajax calls), but want to know what the real issue is here.  

I've used this technique kendo grid + poco (plain old class objects) on another project and this binding action approach all works fine.  So is it kendo + csla model binder problem?

I'll post this into the kendo forums too, but I know I'll get the Csla insights here.

Thanks,

Richard.

 

Here's part of the stack trace.

[MissingMethodException: Cannot create an instance of an interface.]

   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0

   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113

   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232

   System.Activator.CreateInstance(Type type, Boolean nonPublic) +83

   System.Activator.CreateInstance(Type type) +66

   System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +554

 

[MissingMethodException: Cannot create an instance of an interface. Object type 'Csla.Core.IParent'.]

   System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +630

   System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +1136

   System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +633

   Castle.Proxies.DefaultModelBinderProxy.BindModel_callback(ControllerContext controllerContext, ModelBindingContext bindingContext) +45

   Castle.Proxies.Invocations.DefaultModelBinder_BindModel.InvokeMethodOnTarget() +191

   Castle.DynamicProxy.AbstractInvocation.Proceed() +117


Viewing all articles
Browse latest Browse all 764

Trending Articles