我创建了一个非常简单的MVC5.0应用程序,并将其推送到GitHub存储库:https://github.com/marxin/mvc-sample。我的动机是在Linux上使用mono 3.2.3执行应用程序。
我想添加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 Diff:https://github.com/marxin/mvc-sample/commit/ca980adcf1d67e2e74729b27b11c26065dd2567e
你能帮助我必须注册Autofac来启用Razor查看页面的最低要求是什么?
如果我尝试使用aspx模板,一切工作正常。
谢谢你,马丁
发布于 2014-02-02 06:05:47
好的,问题出在web.config引用定义中,请看下面的不同之处:https://github.com/marxin/mvc-sample/commit/3d5d7fef6f0284a96518852e0d892ca6205f5679
顺便说一句。MVC5确实与mono不兼容,但有一些拉取请求可以修复丢失的功能。
谢谢
发布于 2014-02-01 03:38:32
你需要为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...
}https://stackoverflow.com/questions/21488330
复制相似问题