nop 4.1 Plugin Developement - ICategoryService Cannot be found

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
Every Service can be called except ICategoryService. I can clearly see ICategoryService under Nop.Services.Catalog but when calling it it says "ICategoryService cannot be found"


using Microsoft.AspNetCore.Mvc;
using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Domain.Catalog;
using Nop.Plugin.Widgets.MegaMenu.Models;
using Nop.Services.Catalog;
using Nop.Services.Configuration;
using Nop.Services.Media;
using Nop.Web.Framework.Components;
using System.Linq;


namespace Nop.Plugin.Widgets.MegaMenu.Components
{
  [ViewComponent(Name = "MegaMenu")]
  public class MegaMenuViewComponent : NopViewComponent
  {
    private readonly IStoreContext _storeContext;
    private readonly IStaticCacheManager _cacheManager;
    private readonly ISettingService _settingService;
    private readonly IPictureService _pictureService;
    private readonly ICategoryService _categoryService;

    public MegaMenuViewComponent(IStoreContext storeContext,
        IStaticCacheManager cacheManager,
        ISettingService settingService,
        IPictureService pictureService,
        ICategoryService categoryService)
    {
      this._storeContext = storeContext;
      this._cacheManager = cacheManager;
      this._settingService = settingService;
      this._pictureService = pictureService;
      this._categoryService = categoryService;
    }



public IViewComponentResult Invoke(string widgetZone, object additionalData)
    {
      var mCategories = new PublicInfoModel();

      var allCategories = _categoryService.GetAllCategories().Where(x => x.IncludeInTopMenu == true);


Solved. There is a bug in nopcommerce 4.1 for ICategoryService

The implementation in ICategoryService.cs for Nop.Service.Catalog;


public partial interface IList
{
  

Changed to:

public partial interface ICategoryService
{


Cleaned and Rebuilt Solution and all is working. Did nopCommerce forget to rename the service or is it name IList on purpose???
5 years ago
Looks fine to me -

https://github.com/nopSolutions/nopCommerce/blob/develop/src/Libraries/Nop.Services/Catalog/ICategoryService.cs
https://github.com/nopSolutions/nopCommerce/blob/develop/src/Libraries/Nop.Services/Catalog/CategoryService.cs
5 years ago
It appears the error was corrected in a later release of 4.1. When trying to call ICategoryService in the below code I received ICategoryService could not be found.

namespace Nop.Plugin.Widgets.MegaMenu.Components
{
  [ViewComponent(Name = "MegaMenu")]
  public class MegaMenuViewComponent : NopViewComponent
  {
    private readonly IStoreContext _storeContext;
    private readonly IStaticCacheManager _cacheManager;
    private readonly ISettingService _settingService;
    private readonly IPictureService _pictureService;
    private readonly ICategoryService _categoryService;

    public MegaMenuViewComponent(IStoreContext storeContext,
        IStaticCacheManager cacheManager,
        ISettingService settingService,
        IPictureService pictureService,
        ICategoryService categoryService)
    {
      this._storeContext = storeContext;
      this._cacheManager = cacheManager;
      this._settingService = settingService;
      this._pictureService = pictureService;
      this._categoryService = categoryService;
    }


Inspecting Nop.Services.Catalog I found this entry for ICategroyService.

public partial interface IList


Obviously with a declaration like that, ICategoryService certainly wouldn't be found. Maybe NopCommerce shouldn't release versions until they have been fully tested?

Now I need to download and work on the latest version because who knows what else has had to be fixed since I downloaded July's version. SMH.
5 years ago
I think you'll find this was your mistake.

You can see the history of ICategoryService.cs here -

https://github.com/nopSolutions/nopCommerce/commits/develop/src/Libraries/Nop.Services/Catalog/ICategoryService.cs
5 years ago
Yep. The issue was when nop released the beta for 4.1 I downloaded it to test it and never went back to get the release version of 4.1. The files in the beta version were from Nov 17. The files in the release version are from July 2018. My error completely. All is good and thank you for your replies.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.