C# MVC5 Autofac:未创建在处找到的视图

C# MVC5 Autofac:未创建在处找到的视图,c#,razor,mono,autofac,asp.net-mvc-5,C#,Razor,Mono,Autofac,Asp.net Mvc 5,我创建了非常简单的MVC 5.0应用程序,并将其推送到GitHub存储库:。我的动机是使用mono 3.2.3在Linux上执行应用程序 我想添加Autofac NuGet软件包(更准确地说是3.3.0),这对我来说很好。问题是,如果我添加Autofac.Mvc5集成包,Razor将停止工作,并出现以下错误: System.InvalidOperationException The view found at '~/Views/Home/Index.cshtml' was not created

我创建了非常简单的MVC 5.0应用程序,并将其推送到GitHub存储库:。我的动机是使用mono 3.2.3在Linux上执行应用程序

我想添加Autofac NuGet软件包(更准确地说是3.3.0),这对我来说很好。问题是,如果我添加Autofac.Mvc5集成包,Razor将停止工作,并出现以下错误:

System.InvalidOperationException
The view found at '~/Views/Home/Index.cshtml' was not created.

Description: HTTP 500.Error processing request.

Details: Non-web exception. Exception origin (name of application or object): System.Web.Mvc.
Exception stack trace:
at System.Web.Mvc.BuildManagerCompiledView.Render (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) [0x00000] in <filename unknown>:0 at System.Web.Mvc.ViewResultBase.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x00000] in <filename unknown>:0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in <filename unknown>:0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (IList`1 filters, Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in <filename unknown>:0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (IList`1 filters, Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in <filename unknown>:0 
System.invalidoOperationException
未创建在“~/Views/Home/Index.cshtml”中找到的视图。
描述:HTTP 500。处理请求时出错。
详细信息:非web异常。异常源(应用程序或对象的名称):System.Web.Mvc。
异常堆栈跟踪:
在System.Web.Mvc.BuildManagerCompiledView.Render(System.Web.Mvc.ViewContext ViewContext,System.IO.TextWriter writer writer)[0x00000]in:0 at System.Web.Mvc.ViewResultBase.ExecuterResult(System.Web.Mvc.ControllerContext context)[0x00000]in:0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(System.Web.Mvc.ControllerContext ControllerContext,System.Web.Mvc.ActionResult ActionResult)[0x00000]in:0位于System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1筛选器,Int32筛选器索引,System.Web.Mvc.ResultExecutingContext预文本,System.Web.Mvc.ControllerContext ControllerContext,System.Web.Mvc.ActionResult ActionResult)[0x00000]in:0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1筛选器,Int32筛选器索引,System.Web.Mvc.ResultExecutingContext预文本,System.Web.Mvc.ControllerContext ControllerContext,System.Web.Mvc.ActionResult ActionResult)[0x00000]in:0
差异:

您能否帮助我,要启用Razor view页面,Autofac必须注册的最低要求是什么

如果我尝试使用aspx模板,一切正常


谢谢,Martin

您需要为autofac注册IoC容器。请尽快在您的global.asax中注册:

protected void Application_Start()
{
    var builder = new ContainerBuilder();
    builder.RegisterControllers(typeof(MvcApplication).Assembly);
    var container = builder.Build();
    DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

    // Other MVC setup...
}

您需要在您的global.asax中为autofac注册IoC容器:

protected void Application_Start()
{
    var builder = new ContainerBuilder();
    builder.RegisterControllers(typeof(MvcApplication).Assembly);
    var container = builder.Build();
    DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

    // Other MVC setup...
}

好的,问题出在web.config引用定义中,请参见以下差异:

顺便说一句,MVC5确实与mono不兼容,但也有一些pull请求将修复缺失的功能


谢谢

好的,问题出在web.config引用定义中,请参见以下区别:

顺便说一句,MVC5确实与mono不兼容,但也有一些pull请求将修复缺失的功能


谢谢

我添加了您建议的代码:,但没有帮助。我阅读了可以在Autofac wiki上找到的MvcIntegration wiki页面,但它只涉及注射问题的Razor。我只需要使用Razor。我添加了您建议的代码:,但没有帮助。我阅读了可以在Autofac wiki上找到的MvcIntegration wiki页面,但它只涉及注射问题Razor在注射问题上。我只需要工作Razor。注意,mono还不兼容MVC5(但我在这里实现了缺失的部分:,所以你可能想帮助他在许多拉取请求中分割补丁,以便mono团队轻松审查)。注意,mono还不兼容MVC5(但我在这里实现了缺失的部分:,因此您可能希望帮助他将补丁拆分为多个pull请求,以便于mono团队审查)