0
votes

Trying to upgrade a project from MVC3to MVC5, the 3->4 part went well and I could run the project.

However, after updating probably everything for mvc5, I'm getting an exception

Inheritance security rules violated by type: 'Autofac.Integration.Web.Mvc.AutofacControllerFactory'. Derived types must either match the security accessibility of the base type or be less accessible.

on this row of Application_Start() InitContainerProvider();

the method being called:

protected void InitContainerProvider()
        {
            var builder = new ContainerBuilder();
            builder.RegisterControllers(Assembly.GetExecutingAssembly());

            builder.RegisterType<PeriodsProxy>().As<IPeriods>().AsWcfProxy();

            _containerProvider = new ContainerProvider(builder.Build());
            var factory = new AutofacControllerFactory(_containerProvider);

            ControllerBuilder.Current.SetControllerFactory(factory);
        }
1

1 Answers

1
votes

Try the following

protected void InitContainerProvider()
{
    var builder = new ContainerBuilder();

    builder.RegisterModule<AutofacWebTypesModule>();

    builder.RegisterType<PeriodsProxy>().As<IPeriods>().AsWcfProxy();

    builder.RegisterControllers(Assembly.GetExecutingAssembly());

    _containerProvider = new ContainerProvider(builder.Build());
    DependencyResolver.SetResolver(new AutofacDependencyResolver(_containerProvider.ApplicationContainer.BeginLifetimeScope()));
}

This example uses the package NuGet: Autofac.Mvc5