Related to this- Newsletter Checkbox on contact us page in magento 2

I am using magento 2.1.7 version. I created this module and it gives me error as:-

Fatal error: Uncaught TypeError: Argument 1 passed to Stackoverflow\Contact\Helper\Data::__construct() must be an instance of Magento\Framework\App\Helper\Context, instance of Magento\Framework\ObjectManager\ObjectManager given, called in G:\xampp2\htdocs\magento2\test\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php on line 93 and defined in G:\xampp2\htdocs\magento2\test\app\code\Stackoverflow\Contact\Helper\Data.php:34 Stack trace: #0 G:\xampp2\htdocs\magento2\test\vendor\magento\framework\ObjectManager\Factory\AbstractFactory.php(93): Stackoverflow\Contact\Helper\Data->__construct(Object(Magento\Framework\ObjectManager\ObjectManager)) 1 G:\xampp2\htdocs\magento2\test\vendor\magento\framework\ObjectManager\Factory\Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('Stackoverflow\Co...', Array) #2 G:\xampp2\htdocs\magento2\test\vendor\magento\framework\ObjectManager\ObjectManager.php(71): Magento\Framework\ObjectManager\Fac in G:\xampp2\htdocs\magento2\test\app\code\Stackoverflow\Contact\Helper\Data.php on line 34.

How to fixed this?


It is showing that your helper is not using Magento\Framework\App\Helper\Context class instance.

Please clear cache, generation folder too.

Update code like this.

 public function __construct(
    \Magento\Framework\App\Helper\Context $context
  • Thanks. I am working on developer mode. When i apply above change and by deleting var/generation, var/di folders it is working fine. But when i upgrade,compile and deploy it shows previous same error message. How to fix this to compatible with upgrade/compile process?? I used like:- public function __construct( \Magento\Framework\App\Helper\Context $context, Session $customerSession, Subscriber $subscriber ) { $this->customerSession = $customerSession; $this->subscriber = $subscriber; parent::__construct($context); } – Hasitha Anuruddha Aug 30 '17 at 11:36
  • After deploy and compile , once again you need to clear cache folder, because after compile still your var/generation folder contain old data (static). please read the magento 2 offical documentation for more details. – Padhiyar Gaurang Aug 30 '17 at 11:47
  • I tried with this. Unfortunately it is not working. Enabled production mode and checked. But same error. – Hasitha Anuruddha Aug 30 '17 at 13:01

If your M2 mode is on develop mode then remove var/generation and var/di folder


fire below command in your magento root directory

php bin/magento setup:di:compile 

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.