Search code examples
c#asp.net-mvcasp.net-mvc-5autofacautofac-configuration

Mvc 4 to 5 upgrade issue - how to resolve Autofac security rules violation


I upgraded my asp.net web app (targetFramework 4.5.2) from mvc 4 to 5 according to this link. The solution compiles without errors however at runtime I get:

The inheritance security rules were violated when the member "Autofac.Integration.Mvc.AutofacDependencyResolver.GetService (System.Type)" was overwritten. The security access of the overriding method must match the security access of the overwritten method.

I searched the forum but none of the related posts could help me to pin down the origin of the error. Trying to upgrade Autofac.Mcv4 to 5 (as suggested in the posts) failed (-> Autofac.Mcv5 does not target frameWork 4.5.2). Changing the targetFramework to 4.6 and 4.6.1 also did not allow to install Autofac.Mcv5.

Below I have listed the relevant packages installed in the main project:

<packages>
  <package id="Autofac" version="3.5.0" targetFramework="net452" />
  <package id="Autofac.Mvc4" version="3.1.0" targetFramework="net452" />
  <package id="Autofac.WebApi2" version="3.4.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.Providers.Core" version="1.2" targetFramework="net45" />
  <package id="Microsoft.AspNet.Providers.LocalDB" version="1.1" targetFramework="net45" />
  <package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net452" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net45" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.OData" version="5.2.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Tracing" version="5.2.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.0" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net452" />
  <package id="Microsoft.jQuery.Unobtrusive.Ajax" version="2.0.30116.0" targetFramework="net45" />
  <package id="Microsoft.jQuery.Unobtrusive.Validation" version="2.0.30116.0" targetFramework="net45" />
  <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net452" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
  <package id="Modernizr" version="2.6.2" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
  ... and others
</packages>

Also note, that the solution has several projects (two have references to Autofac). Any help to pin down the origin of or to solve the error would be appreciated.


Solution

  • You forgot to update the Autofac.Mvc4 package to Autofac.Mvc5.