Kevin R.
Kevin R.

Reputation: 3581

Autofac Exception: Could not load type from assembly

Issue

While building an Autofac Container, upon registering an interface implementation, Autofac would throw an exception:

Registration:

protected override void Load(ContainerBuilder builder)
{
    var assembly = typeof(MyModule).Assembly;

    builder.RegisterAssemblyTypes(assembly)
        .Where(x => x.Name.EndsWith("Procedure")
        .AsImplementedInterfaces();

    base.Load(builder);
}

Error:

Could not load type from assembly

Attempted Solutions:

Upvotes: 0

Views: 2163

Answers (1)

Kevin R.
Kevin R.

Reputation: 3581

Solution

After searching Google, StackOverflow, Autofac documentation, and my soul, the closest I could find to my issue was this answer concerning the Global Assembly Cache (GAC) posted to this question concerning a container being build for testing purposes.

This lead me to think wrong assemblies. In our environment, we use Nuget packages frequently for our core interfaces and infrastructure. I checked that I was using the latest version of the package in my Service layer, so I was still stumped until I dug just a bit further.

The Culprit

In the end, the issue came down to the Nuget packages. The presentation layer of my solution, which was registering components via Autofac, had an outdated version of the Nuget package which contained the interface definitions. By updating the Nuget package in the presentation layer to match that of the Service layer, the problem disappeared.

Upvotes: 1

Related Questions