2

I created very simple MVC 5.0 application that I push to GitHub repository: https://github.com/marxin/mvc-sample. My motivation is to execute app on Linux with mono 3.2.3.

I would like to add Autofac NuGet package (more precisely 3.3.0), that works fine for me. Problem is that if I add Autofac.Mvc5 integration package, Razor stops working with following error:

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

Could you please help me what's the necessary minimum that must be registered for Autofac to enable Razor view pages?

If I try aspx template, all works fine.

Thank you, Martin

marxin
  • 715
  • 1
  • 10
  • 18
  • beware, mono is not compatible with MVC5 yet (but I guy implemented the missing pieces here: https://github.com/mono/mono/pull/862 , so you might want to help him split the patches in many pull requests for easy review by the mono team) – knocte Feb 01 '14 at 16:14

2 Answers2

3

OK, the problem was in web.config reference definition, please see following diff: https://github.com/marxin/mvc-sample/commit/3d5d7fef6f0284a96518852e0d892ca6205f5679

Btw. MVC5 is really not compatible with mono, but there are pull requests that will fix missing features.

Thanks

marxin
  • 715
  • 1
  • 10
  • 18
1

You need to register your IoC container for autofac. In your 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...
}
Pete
  • 3,842
  • 3
  • 31
  • 42
  • I added code you suggested: https://github.com/marxin/mvc-sample/blob/84c9b2aabee4df0c7c67ec7005e2ffb92fdf2293/Site/Global.asax.cs, but it does not help. I read MvcIntegration wiki page that can be found at Autofac wiki, but it only touches Razor in question of injection. I just need working Razor. – marxin Jan 31 '14 at 20:11