Autofac Exception: Could not load type from assembly

雨燕双飞 提交于 2019-12-12 03:04:12

问题


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:

  • Clean build / Rebuild
  • Deleting bin/obj directories
  • Changing manner in which I was assigning the assembly
  • Changing manner in which I was performing registrations
  • Restarting Visual Studio

回答1:


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.



来源:https://stackoverflow.com/questions/37734742/autofac-exception-could-not-load-type-from-assembly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!