0

我有一个包含 ASP.NET Core 项目和 Windows 服务项目以及数据访问和业务 dll 的解决方案。我使用 autofac 进行依赖注入。在 windows 服务项目中,我加载包含 autofac 模块的 dll,如下所示:

    Assembly.Load("EnterpriseDirectory.Data");
    Assembly.Load("EnterpriseDirectory.Web.Business");
    builder.RegisterAssemblyModules(AppDomain.CurrentDomain.GetAssemblies()
        .Where(w => w.GetName().Name == "EnterpriseDirectory.Data"
        || w.GetName().Name == "EnterpriseDirectory.Web.Business").ToArray());

模块已正确注册,一切正常。但是,如果我在 ASP.NET Core 应用程序中执行相同操作,程序集会加载以下异常并且模块未注册:

DefinedTypes = '((System.Reflection.RuntimeAssembly)ass).DefinedTypes' threw an exception of type 'System.Reflection.ReflectionTypeLoadException'

我尝试将 Assembly.Load 方法包装到 try catch 块中,但没有捕获到异常。我究竟做错了什么?

4

0 回答 0