无法创建接口实例

发布于 2024-12-21 03:00:18 字数 4333 浏览 2 评论 0原文

安装配置文件 1.1 后,向用户内容类型添加至少一个字段,然后转到用户模块并单击添加新用户,单击保存,您应该会收到此错误。任何帮助将不胜感激。

“/OrchardLocal”应用程序中的服务器错误。

无法创建接口的实例。 描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。

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


版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.237

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陈独秀 2024-12-28 03:00:18

哇,今天遇到了完全相同的错误(但不确定那是否是同一个模块)!

这是视图模型之一中的错误。有人在那里放置了一个接口,而不是类(例如,IUser 而不是 UserPartRecord)。模型绑定器喊叫,因为它无法创建要绑定表单参数的对象实例。

您唯一的选择是将该参数的类型(您必须找出哪一个)更改为具体类型。最快的方法是创建一个实现该接口的简单类,并用它替换参数类型。

编辑:讨论了(并解决了)类似的问题此处此处

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.

三岁铭 2024-12-28 03:00:18

我开始在 MVC ASP.Net 4.6 应用程序中遇到此异常。我花了一些时间,但我终于意识到我已将 MVC 控制器 API 调用从 更改为

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

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

正在避免 R# 警告的 IEnumerable 的多重枚举。经验教训:在这种情况下不要使用 IReadOnlyList。

这是完整的异常:

[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) +119
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& 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

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& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +119
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& 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
沧桑㈠ 2024-12-28 03:00:18

我遇到了与 (MVC 5) + (Ninject3.2) 完全相同的问题。整个DI准备工作非常典型和标准,只是无法使其发挥作用。最后,我这样做了:

  1. 为你的控制器创建一个默认的 CTOR;
  2. 在 CTOR 中,添加如下行:

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

我知道这只是一种解决方法,但我认为 MVC 5 中有关控制器对象实例化的内容已发生变化。以后会挖出来的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文