Skip to main content
 首页 » 编程设计

c#之没有为此对象定义无参数构造函数-nop commerce 2.6

2024年02月06日11sxdcgaq8080

我正在使用 nop 商务。

我向目录 Controller 添加了一个新的服务类。

然后它得到这个错误。

No parameterless constructor defined for this object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
 
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object. 
 
Source Error: 
 
 
Line 3:  @foreach (var widget in Model) 
Line 4:  { 
Line 5:      @Html.Action(widget.ActionName, widget.ControllerName, widget.RouteValues) 
Line 6:  } 
 
 
Source File: f:\project\sitename\Presentation\Nop.Web\Views\Widget\WidgetsByZone.cshtml    Line: 5  

我改变了这个 Controller 。

public CatalogController(ICategoryService categoryService,  
            IManufacturerService manufacturerService) 

到

public CatalogController(ICategoryService categoryService,  
            IManufacturerService manufacturerService, IbookService bookService) 

然后就报错了。

如何解决?

请您参考如下方法:

如果您在这里使用的IProductService 是原来的nopCommerce IProductService,我找不到它会抛出错误的原因。但是如果是自己写的服务,那么就需要在DependencyRegistrar.cs中注册。您可以在 nopCommerce 中查找有关如何注册您自己的依赖项的当前示例。 :)