None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'

You have regiestered your EmailService two times.

Once in the web.config and once with

builder.RegisterType<EmailService>().As<IEmailService>().SingleInstance();

If you have the line above in the Core.ModuleInstaller then it will override the web.config configuration. And because here you haven't specified the parameter Autofac throws an exception.

So to solve this just remove the EmailService registration from the Core.ModuleInstaller module.

If you use the Core.ModuleInstaller multiple places and you need to have the EmailService registration there then you need to change the order of the Module loading:

var builder = new ContainerBuilder();
builder.RegisterModule<Core.ModuleInstaller>();
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));

or tell Autofac to not override the registration of EmailService if it already exists with PreserveExistingDefaults:

builder.RegisterType<EmailService>().As<IEmailService>()
       .SingleInstance().PreserveExistingDefaults();

I had created a constructor where there was none before and made it private, therefore there was default constructor so I got this error. Had to make my constructor public.

Tags:

C#

Autofac