I have a Controller that contains the following:


use Magento\Backend\App\Action;
use Magento\TestFramework\ErrorLog\Logger;
use Magento\MediaStorage\Model\File\UploaderFactory;
use MyNamespace\Slider\Model\SliderImage;

class Save extends \Magento\Backend\App\Action

    /** @var UploaderFactory */
    protected $uploaderFactory;

    /** @var SliderImage */
    protected $imageModel;

    public function __construct(
        Action\Context $context,
        UploaderFactory $uploaderFactory,
        SliderImage $imageModel
        $this->uploaderFactory = $uploaderFactory;
        $this->imageModel = $imageModel;


I am using this to save a form in the admin. It was working properly without the UploaderFactory and SliderImage in the __contruct.

I am now trying to add an Image field to the form. I have added the dependencies, UploaderFactory and SliderImage and now get the error:

Uncaught TypeError: Argument 2 passed to MyNamespace\Slider\Controller\Adminhtml\Image\Save::__construct() must be an instance of Magento\MediaStorage\Model\File\UploaderFactory, none given, called in /var/www/html/generated/code/MyNamespace/Slider/Controller/Adminhtml/Image/Save/Interceptor.php on line 14 and defined in /var/www/html/app/code/MyNamespace/Slider/Controller/Adminhtml/Image/Save.php:19 Stack trace: #0 /var/www/html/generated/code/MyNamespace/Slider/Controller/Adminhtml/Image/Save/Interceptor.php(14): MyNamespace\Slider\Controller\Adminhtml\Image\Save->__construct(Object(Magento\Backend\App\Action\Context)) #1 /var/www/html/lib/internal/Magento/Framework/ObjectManager/Factory/AbstractFactory.php(111): MyNamespace\Slider\Controller\Adminhtml\Image\Save\Interceptor->__construct(Object(Magento\Backend\App\Action\Context)) #2 /var/www/html/lib/internal/Magento/Framework/ObjectManager/Factory/Dynamic/Developer.php(66): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('MyNamespace\Slider...', Array)


If you are using Magento 2.1.9 or less than clear var/generation, var/cache directory and if you are 2.2.0 or greater than remove generated/code and generated/metadata folder.


|improve this answer|||||
  • I was looking for var/generated for quite some time. Didn't realize 2.2.0 moved the location. I ran bin/magento setup:di:compile and it fixed my issue. But now I know where these folders are so thanks :) – Shawn Northrop Nov 21 '17 at 6:22

Clear var/generation folder and refresh, the error will be gone.

|improve this answer|||||
  • 1
    From Magento 2.2, generation folder is under root generated – Khoa TruongDinh Nov 21 '17 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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