2020-09-12

参数错误导致的依赖注入的错误提示:A suitable constructor for type MyApp.OptionMethodSetting could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

前几天做一个项目,发生一个奇怪的错误

System.InvalidOperationException:"A suitable constructor for type 'MyApp.OptionMethodSetting' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor." 

 

通常情况下这是由于依赖注入的实现无法访问到造成的,可是实际看了代码,该访问的都是public,而且这段代码是从另一个项目带过来的,另一个项目跑的好好的,这还真是奇怪了。

中间折腾了半天,发现是由于这个中间件有一个参数传递了null造成的。

 

就是这个罪魁祸首。

怎么会传null呢?

项目是拷过来的,所以很多这边用不上的配置,就删除了,结果导致这个也在appsetting.json里被误删了,结果导致读取时不存在,传递了null

 

 这个是祸根。

记录下,备忘。下次发生这样的问题的时候,查下是不是参数有问题。

 

参数错误导致的依赖注入的错误提示:A suitable constructor for type MyApp.OptionMethodSetting could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.3suisses快速增强产品调研能力30天打造爆款的真正核心-PPC实战技巧Shopify网站地图是什么?如何将网站地图提交给Google?如何为我的产品启用Wish Express?亚马逊Q2搜索广告业务飙升,最受欢迎的广告类型有哪些?解锁品类、降费率、出周报,多措并举,Lazada让越南不再"难"(附热搜词)2019泉州产业带跨境峰会顺利召开!

No comments:

Post a Comment