0

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?

1

2 Answers 2

0

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
    )
{
      parent::__construct($context);
}
3
  • 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); } Aug 30, 2017 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. Aug 30, 2017 at 11:47
  • I tried with this. Unfortunately it is not working. Enabled production mode and checked. But same error. Aug 30, 2017 at 13:01
0

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

OR ELSE

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 and acknowledge you have read our privacy policy.

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