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?

1 Answer 1

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
4
  • 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, 2016 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 Sep 1, 2016 at 12:03
  • 1
    Also getting the same as @user3014311 now. Uninstalled all autofac and went from start. All projects targetting 4.5. Sep 13, 2016 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, 2016 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.