this is happening when I install megamenu from template monster and updated to Magento 2.2.6 any ideas? full error below

Fatal error: Uncaught TypeError: Argument 2 passed to Magento\Catalog\Plugin\Block\Topmenu::__construct() must be an instance of Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory, instance of Magento\Catalog\Model\ResourceModel\Category\CollectionFactory given, called in /home/olabrava/public_html/app/code/TemplateMonster/Megamenu/Plugin/Block/Topmenu.php on line 27 and defined in /home/olabrava/public_html/vendor/magento/module-catalog/Plugin/Block/Topmenu.php:47 Stack trace: #0 /home/olabrava/public_html/app/code/TemplateMonster/Megamenu/Plugin/Block/Topmenu.php(27): Magento\Catalog\Plugin\Block\Topmenu->__construct(Object(Magento\Catalog\Helper\Category), Object(Magento\Catalog\Model\ResourceModel\Category\CollectionFactory), Object(Magento\Store\Model\StoreManager), Object(Magento\Catalog\Model\Layer\Resolver)) #1 /home/olabrava/public_html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(111): TemplateMonster\Megamenu\Plugin\Block\Topmenu->__construct(Object(Magento\Catalo in /home/olabrava/public_html/vendor/magento/module-catalog/Plugin/Block/Topmenu.php on line 47

  • did you run php bin/magento setup:upgrade command ? Oct 11, 2018 at 17:37
  • run command rm -rf generated/* first and then run setup command php bin/magento setup:upgrade Oct 11, 2018 at 17:59
  • did both and still not working Oct 11, 2018 at 19:05

1 Answer 1


Open vendor/magento/module-catalog/Plugin/Block/Topmenu.php

The constructor of this class looks like

    public function __construct(
        \Magento\Catalog\Helper\Category $catalogCategory,
        \Magento\Catalog\Model\ResourceModel\Category\StateDependentCollectionFactory $categoryCollectionFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Catalog\Model\Layer\Resolver $layerResolver

Now, open TemplateMonster\Megamenu\Plugin\Block\Topmenu and take a look at its __construct method.

Your first check should be if parent::_construct() is called.

If it does, what parameters are send there?

Your checks here:

A. Does parent::__construct receives 4 parameters?

B. What variable is send as a second parameter?

This last one is actually the problem: the second parameter that you send is NOT of type


but of type


Inject the correct type for the second parameter, confirm that the rest are send as expected, re-compile if you must, and you are done :).

I hope this helps.

  • You are welcome.
    – Marjan
    Oct 11, 2018 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.