我的项目是跨平台项目。其中包含3个Project 2 .Net-standard 2.0和一个带有.Net-framework 4.6.2的启动项目。
最新的Autofac版本(5.2.0)不支持.NetFramework 4.6.2。
我遇到了错误
autofac.dll中的“ autofac.core.registration.componentnotregisteredexception”生成器。Build()无法实例化该类对象。
错误信息:
Autofac.dll中发生类型为'Autofac.Core.Registration.ComponentNotRegisteredException'的异常,但未在用户代码中处理。其他信息:所请求的服务'ShipPageObjects.PageObjects.Login.LoginResolvePage'未注册。为避免此异常,请注册一个组件以提供服务,或者使用IsRegistered()检查服务注册,或者使用ResolveOptional()方法解决可选的依赖项。
var builder = new ContainerBuilder();
builder.RegisterModule(new ContainerConfig());
builder.RegisterInstance(testConfig).As<ITestConfig>();
builder.RegisterModule(new ShipmentmentTest(testConfig));
builder.RegisterModule(new MaterialTest(testConfig));
Container = builder.Build();
这不是Autofac 5.2.0和.NET Framework 4.6.2的错误。例外是它告诉您ShipPageObjects.PageObjects.Login.LoginResolvePage
尚未注册。您可能会将其注入到您已注册但尚未注册LoginResolvePage的内容中。
Autofac非常擅长告诉您在这些情况下失败的原因。您可以一一遍历地查看异常,然后根据需要添加的内容进行添加,或者追溯您的注入并确保所有内容都已注册。我建议做后者,并使用前者来完成它。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句