27

I've got an ASP.NET MVC application using Autofac.

I've added the appropriate packages via:

Install-Package Autofac
Install-Package Autofac.Mvc4

When I ran the web application, this error was throw:

Inheritance security rules violated while overriding member: 'Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(System.Type)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

How can this be solved?

p.campbell
  • 98,673
  • 67
  • 256
  • 322

1 Answers1

53

I had installed Autofac for MVC 4 when the project type was actually MVC 5.

To solve this, I ran Uninstall-Package Autofac.Mvc4 and

Install-Package Autofac.Mvc5
Luis
  • 5,979
  • 2
  • 31
  • 51
p.campbell
  • 98,673
  • 67
  • 256
  • 322
  • Thanks a bunch! Having separate ASP.NET and MVC versions can get pretty confusing now that they're advertising ASP.NET 5. – cwharris Jul 28 '16 at 16:36
  • 3
    Facing the same issue, but I cannot install Autofac.Mvc5 . Error: Install-Package : Could not install package 'Autofac 4.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework – user3014311 Sep 01 '16 at 12:03
  • 1
    Also getting the same as @user3014311 now. Uninstalled all autofac and went from start. All projects targetting 4.5. – JustAnotherDeveloper Sep 13 '16 at 13:08
  • This error is due to the target framework. In order to install Autofac 4 the project must target .NET Framework 4.6+ – Jano Nov 21 '16 at 23:02