简体   繁体   English

使用MVC 5和StructureMap“找不到入口点”

[英]“Entry point was not found” with MVC 5 and StructureMap

I'm using StructureMap 2.6.4.1 with a new MVC 5 project. 我正在使用StructureMap 2.6.4.1和一个新的MVC 5项目。 Previously, in MVC 4 projects, our setup works fine. 以前,在MVC 4项目中,我们的设置工作正常。

We have a SM controller factory, such as this: 我们有一个SM控制器工厂,例如:

public class StructureMapControllerFactory : DefaultControllerFactory
    {
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            var instance = ObjectFactory.GetInstance(controllerType) as IController;

            if (instance == null)
            {
                return base.GetControllerInstance(requestContext, controllerType);
            }

            return instance;
        }
    }

And in the Global.asax.cs , in app start, we set it like this: Global.asax.cs中 ,在app start中,我们设置如下:

    ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());

The issue is, if this last line is enabled in app start, we get this:

**[EntryPointNotFoundException: Entry point was not found.]**
   System.Web.Mvc.IControllerFactory.GetControllerSessionBehavior(RequestContext requestContext, String controllerName) +0
   System.Web.Mvc.MvcRouteHandler.GetSessionStateBehavior(RequestContext requestContext) +131
   System.Web.Mvc.MvcRouteHandler.GetHttpHandler(RequestContext requestContext) +33
   System.Web.Mvc.MvcRouteHandler.System.Web.Routing.IRouteHandler.GetHttpHandler(RequestContext requestContext) +10
   System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context) +9767524
   System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e) +82
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

Again, this works just fine in our MVC 4 projects, but I cannot find enough information that relates to MVC 5. I'd hate to revert back to MVC 4, but will if I have to. 同样,这在我们的MVC 4项目中运行得很好,但是我找不到与MVC 5有关的足够信息。我不想恢复到MVC 4,但是如果必须的话。 Thanks. 谢谢。

It's may a version of assembly problem 这可能是装配问题的一个版本

You need to change the assembly to latest version 您需要将程序集更改为最新版本

see this Entry point was not found exception 看到这个入口点未被发现异常

Fixed my own issue. 修复了我自己的问题。 For some reason, while I created a new MVC5 project, it was still referencing the old WebPages 2.0 and MVC 4 assemblies. 出于某种原因,当我创建一个新的MVC5项目时,它仍然引用旧的WebPages 2.0和MVC 4程序集。 No idea why. 不知道为什么。 I ran an update via nuget and it fixed the issues (it also updated other existing MVC4 apps to 5 without issue). 我通过nuget运行了更新,它修复了问题(它还将其他现有的MVC4应用程序更新为5个没有问题)。

Ramesh, technically your answer is correct. 拉梅什,从技术上讲,你的答案是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM