title: ASP.net MVC 4 and Autofac error - Inheritance security rules violated while overriding member
body: <p>I am getting some strange error while configuring Autofac on ASP.MVC 4. I have worked with Autofac on MVC 4 on many other projects successfully. This MVC project is in .Net 4.5.2 and I am referencing the following Autofac libraries from nuget:</p>
  
  <p>Autofac version=3.5.2 </p>
  
  <p>Autofac.Mvc4 version=3.1.0 </p>
  
  <p>The error that I am getting is:</p>
  
  <p>"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."</p>
  
  <p>The weird thing is that my code is even not called that this error is fired!! My code is as below:</p>
  
  <pre><code>protected void Application_Start()
      {
          AreaRegistration.RegisterAllAreas();
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
          BundleConfig.RegisterBundles(BundleTable.Bundles);
  
          try
          {
              AutofacDependencyResolverHelper.RegisterAutofac();
          }
          catch (Exception ex)
          {
              Trace.Write(ex.Message);
              throw;
          }
  
      }
  
  
       public class AutofacDependencyResolverHelper
  {
      public static void RegisterAutofac()
      {
          var container = GetContainer();
          DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
      }
  
      public static IContainer GetContainer()
      {
          var assemblies = new List&lt;Assembly&gt;();
          assemblies.Add(Assembly.Load("Core.Infrastructure"));
          assemblies.Add(Assembly.Load("Core.GenericRepository"));
          assemblies.Add(Assembly.Load("Core.Common"));
          assemblies.Add(Assembly.Load("CRM.Interfaces"));
          assemblies.Add(Assembly.Load("CRM.Data"));
          assemblies.Add(Assembly.Load("CRM.Dtos"));
          assemblies.Add(Assembly.Load("CRM.Entities"));
          assemblies.Add(Assembly.Load("CRM.Business"));
  
          var builder = new ContainerBuilder();
          builder.RegisterAssemblyTypes(assemblies.ToArray()).AsImplementedInterfaces();
          builder.RegisterControllers(Assembly.Load("CRM.Web.Mvc4"));
          var container = builder.Build();
          return container;
      }
  }
  </code></pre>
  
  <p>Not sure what this error is? Any comments will be appreciated. I have found some other questions but they are related to MVC5:</p>
  
  <p><a href="https://stackoverflow.com/questions/22696246/solving-autofac-issue-inheritance-security-rules-violated-while-overriding-membe">Solving Autofac issue Inheritance security rules violated while overriding member GetService</a></p>
  
  <p><strong>Updated with full config:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;packages&gt;
    &lt;package id="angularjs.TypeScript.DefinitelyTyped" version="4.2.7" targetFramework="net46" /&gt;
    &lt;package id="Antlr" version="3.4.1.9004" targetFramework="net46" /&gt;
    &lt;package id="Autofac" version="3.5.2" targetFramework="net46" /&gt;
    &lt;package id="Autofac.Mvc4" version="3.1.0" targetFramework="net46" /&gt;
    &lt;package id="bootstrap" version="3.0.0" targetFramework="net46" /&gt;
    &lt;package id="jQuery" version="1.10.2" targetFramework="net46" /&gt;
    &lt;package id="jquery.TypeScript.DefinitelyTyped" version="0.0.1" targetFramework="net46" /&gt;
    &lt;package id="jQuery.Validation" version="1.11.1" targetFramework="net46" /&gt;
    &lt;package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net46" /&gt;
    &lt;package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net46" /&gt;
    &lt;package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net46" /&gt;
    &lt;package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net46" /&gt;
    &lt;package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net46" /&gt;
    &lt;package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" /&gt;
    &lt;package id="Modernizr" version="2.6.2" targetFramework="net46" /&gt;
    &lt;package id="Newtonsoft.Json" version="6.0.4" targetFramework="net46" /&gt;
    &lt;package id="Respond" version="1.2.0" targetFramework="net46" /&gt;
    &lt;package id="WebGrease" version="1.5.2" targetFramework="net46" /&gt;
  &lt;/packages&gt;
  </code></pre>