1

On Magento 2.1 when installing an extension, the error occurs when compilation:

Total Errors Count: 1
Errors during compilation:
    Magebuzz\Socialshare\Block\Socialshare
        Incorrect dependency in class Magebuzz\Socialshare\Block\Socialshare in /home/webadmin/public_html/app/code/Magebuzz/Socialshare/Block/Socialshare.php
\Magento\Framework\UrlInterface already exists in context object

Can anyone help?

2 Answers 2

5

The error is self-explained.

Magebuzz\Socialshare\Block\Socialshare block class re-injected the dependency \Magento\Framework\UrlInterface in its constructor.
We can find the original injection from Magento\Framework\View\Element\AbstractBlock.

So to solve it, remove the \Magento\Framework\UrlInterface from the constructor in your custom block class Magebuzz\Socialshare\Block\Socialshare

4
  • Yes, but what can I do to solve this?
    – DevAnd
    Commented May 2, 2017 at 14:26
  • Remove \Magento\Framework\UrlInterface from the constructor in your custom block class - Magebuzz\Socialshare\Block\Socialshare. Commented May 2, 2017 at 14:29
  • @DevAnd Is it okay? The compilation error is gone? Commented May 2, 2017 at 14:53
  • this is a good answer. Read the post from maghamed in github.com/magento/magento2/issues/6114. It just mean that this is already injected and ready to use. No need to reinject it and maybe cause issues. Commented Aug 31, 2017 at 0:40
0

there is a discussion about context on github you can review it on: https://github.com/magento/magento2/issues/6114

for latest version 2.2-develop this validation was removed, there is a pull request that is already merged: https://github.com/magento/magento2/pull/8955

so any future execution of: bin/magento setup:di:compile won't throw errors like:

Total Errors Count: 1
Errors during compilation:
    Magebuzz\Socialshare\Block\Socialshare
        Incorrect dependency in class Magebuzz\Socialshare\Block\Socialshare in /home/webadmin/public_html/app/code/Magebuzz/Socialshare/Block/Socialshare.php
\Magento\Framework\UrlInterface already exists in context object

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.