我有一个ASP.NET核心项目和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块中,但没有捕获任何异常 . 我究竟做错了什么?