Cannot create an instance of an interface
Asked Answered
R

3

7

after install profile 1.1, add at least one field to the User Content Types then go to the Users module and click on Add a new user, click save and you should get this error. any help would be appreciate.

Server Error in '/OrchardLocal' Application.

Cannot create an instance of an interface. 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.MissingMethodException: Cannot create an instance of an interface.

Source Error: 


Line 146: public void EndProcessRequest(IAsyncResult result) {
Line 147: try {
Line 148: _httpAsyncHandler.EndProcessRequest(result);
Line 149: }
Line 150: finally {


Source File: C:\Users\rspaulino\Desktop\src\Orchard\Mvc\Routes\ShellRoute.cs Line: 148 

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) +98
    System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) +241
    System.Activator.CreateInstance(Type type, Boolean nonPublic) +69
    System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +199
    System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +572
    System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +449
    System.Web.Mvc.DefaultModelBinder.GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder) +17
    System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +399
    System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +93
    System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model) +53
    System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +1367
    System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +449
    System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +317
    System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +117
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
    System.Web.Mvc.Controller.ExecuteCore() +116
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
    System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
    System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
    System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
    System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
    Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in C:\Users\rspaulino\Desktop\src\Orchard\Mvc\Routes\ShellRoute.cs:148
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8963149
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +

184


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.237

Raceway answered 13/12, 2011 at 14:41 Comment(3)
Did you try to contact the author of that module? This looks like a bug report, not a question.Bayne
yes I did but didn't get any type of support.Raceway
That sucks. Well, I guess your only option is to fix their code yourself then.Bayne
C
15

Wow, ran into exactly the same error today (but not sure if that was the same module)!

It's a bug in one of the view models. Someone had put an interface there instead of class one (eg. IUser instead of UserPartRecord). Model binder shouts because it cannot create an instance of an object to bind form parameter(s) to.

Your only option is to change the type of that parameter (which one - you have to find out) to a concrete type. The quickest way would be to create a simple class implementing that interface and replace the parameter type with it.

EDIT: A similar problem was discussed (and solved) here and here.

Consternate answered 21/12, 2011 at 1:52 Comment(1)
It seems that an interface is allowed as the type for the @model directive in views, however this error is raised if an interface is the type of a parameter in controller methods.Xylidine
I
4

I started getting this exception in an MVC ASP.Net 4.6 application. It took me some time, but I finally realized that I had change my MVC Controller API call from

[HttpPost]
public async Task<ActionResult> DoStuff(IEnumerable<string> ids){ ... }

To

[HttpPost]
public async Task<ActionResult> DoStuff(IReadOnlyList<string> ids){ ... }

I was avoiding the multiple enumeration of an IEnumerable that R# warns about. Lesson Learned: Don't use IReadOnlyList in this instance.

Here's the full exception:

[MissingMethodException: Cannot create an instance of an interface.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark) +119
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark) +247
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +11
System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +197
Ipoh answered 8/3, 2018 at 17:35 Comment(1)
Got into that myself too. You could use IList or ICollectionElegist
E
-1

I ran into exactly same problem with (MVC 5) + (Ninject3.2). The whole DI preparation is very typical and standard, and just cannot make it working. Finally, I did this:

  1. Create a default CTOR to your controler;
  2. In CTOR, add a line like this:

    repository=DependencyResolver.Current.GetService(typeof(IYourinterface)) as IYourinterface;
    

I know it is just a workaround, but I think something has been changed in MVC 5 about controller object instantiation. Will dig it out later.

Ecbolic answered 26/9, 2014 at 21:13 Comment(1)
This doesn't really solve the problem being discussed here... where the item is trying to be resolved in the method, not the constructorShrapnel

© 2022 - 2024 — McMap. All rights reserved.