Fatal error: Cannot instantiate interface

  • My magento store is throwing this error:

    Fatal error: Cannot instantiate interface Magento\Framework\View\Design\Theme\ResolverInterface in /Library/WebServer/Documents/magento/vendor/magento/framework/ObjectManager/Factory/Dynamic/Developer.php on line 73

    I don't know why it started to appear. I made no new module installation. The store was working fine.

    I've check file permissions and I see no issue there. Also delete the /var/ dir and, I think, all folders/files where created.

    [EDIT] The preference is defined vendor/magento/magento2-base/app/etc/di.xml

    <preference for="Magento\Framework\View\Design\Theme\ResolverInterface" type="Magento\Theme\Model\Theme\Resolver" /> 
    

    i hope in ur custom module or code your trying to use Magento\Framework\View\Design\Theme\ResolverInterface in constructor or object manager

    @PradeepKumar No. I'm not.

    clear your cache and the contents of `var/generation`.

    @Marius as stated in the question, I've already removed the /var/* folder completely.

    Sorry. I missed that line.

  • If you use redis, run:


    redis-cli flushall
    



    If you also use an environment like ansible (lxc - server), you'll need to do that command in container. Plus I did the following:

    • Clear var/generation
    • Clear var/cache
    • Enable Magento modules: bin/magento module:enable --all
    • Compile DI bin/magento setup:di:compile

    there were so many misleading solutions out there and this worked right away

    Enable Magento modules: bin/magento module:enable --all - Worked for me

    NO! It`s not good practice! bin/magento module:enable --all is like chmod -R 777 :(

    Worked like a charm. Was using a redis container. using flushall resolved the issue

    flushing the redis cache solved it, even though that project has not even redis configured. I use redis for another shop though.

    Thanks worked, I had to also remove directories from var/ folder

    thx redis flush was the solution for me as well.

    Does anyone have information on *why* this works? Why would redis be causing setup:upgrade to fail?

  • I had this error and it was solved by clearing the var folder and then running setup:upgrade. If this doesn't solve it then look for errors in di.xml files

    worked for me, specifically `var/cache`

    Thanks `redis-cli flushall` worked for me.

  • Run following command and check.

    rm -rf generated
    
    rm -rf var/*
    

    Worked for me.

  • This worked for me :

     sudo apt-get install php-intl
    
     sudo service apache2 reload
    
  • Clear the cache rm -rf var/cache

    If redis enabled, clear redis db using command line:

    $> redis-cli
    $> flushall
    
  • In my case, I had to remove a module and I simply deleted the files of the module without following proper methods and then this error was on screen everywhere. After searching much I ended up to replace the files of the module back to same directory and deleted all required folders from var and ran the following commands.

    php bin/magento setup:upgrade
    php bin/magento setup:static-content:deploy
    

    and all was fixed. I then followed proper ways to remove the module. Hope this saves someones time. :-)

  • This error could also because of enabling or disabling the modules directly in app/etc/config.php especially when to enable or disable core Magento modules. The best thing to do in such case would be to clear your cache, flush redis cache, restart varnish & php-fpm. And it works.

  • Same problem I was faced when updating the Magento version 2.3.3. so I replace the app/etc/di.xml file content help with below path. https://github.com/magento/magento2/blob/ddf42caaf25311f10b23b95a92746f99943e045e/app/etc/di.xml#L212

    My issue is resolved now

  • This error is created when you try creating (new) an object (class) that is in fact and interface. This normally happens when you have not overridden the interface for a class in the di.xml file. Or have overridden the in the di.xml in the adminhtml directory and are trying to use the interface in the frontend.

    interface MyInterface{
       pubic function getVariable(): int
    }
    
    class MyClass 
    implements MyInterface{
    
       protected $variable;
    
       pubic function getVariable(){
          return $this->variable;
       }
    }
    
    $variable = new MyInterface();
    
  • The problem might be related to the file app/etc/di.xml.

    In my case I accidentially overwrote it with the file of another project. After replacing it, it worked again!

    These two lines were missing in my broken di.xml:

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        ...
        <preference for="Magento\Framework\Interception\ConfigLoaderInterface" type="Magento\Framework\Interception\PluginListGenerator" />
        <preference for="Magento\Framework\Interception\ConfigWriterInterface" type="Magento\Framework\Interception\PluginListGenerator" />
    

    There was also a difference in the PluginList Class:

    Broken di.xml:

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    ...
        <type name="Magento\Framework\Interception\PluginList\PluginList">
            <arguments>
                <argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Config</argument>
                <argument name="reader" xsi:type="object">Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy</argument>
                <argument name="cacheId" xsi:type="string">plugin-list</argument>
                <argument name="scopePriorityScheme" xsi:type="array">
                    <item name="first" xsi:type="string">global</item>
                </argument>
            </arguments>
        </type>
     ...
    

    Working di.xml:

    Please make sure that it looks like this:

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    ...
        <type name="Magento\Framework\Interception\PluginList\PluginList">
            <arguments>
                <argument name="cache" xsi:type="object">Magento\Framework\App\Cache\Type\Config</argument>
                <argument name="reader" xsi:type="object">Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy</argument>
                <argument name="cacheId" xsi:type="string">plugin-list</argument>
                <argument name="scopePriorityScheme" xsi:type="array">
                    <item name="primary" xsi:type="string">primary</item>
                    <item name="first" xsi:type="string">global</item>
                </argument>
            </arguments>
        </type>
        <type name="Magento\Framework\Interception\PluginListGenerator">
            <arguments>
                <argument name="reader" xsi:type="object">Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy</argument>
                <argument name="logger" xsi:type="object">\Psr\Log\LoggerInterface\Proxy</argument>
                <argument name="scopePriorityScheme" xsi:type="array">
                    <item name="primary" xsi:type="string">primary</item>
                    <item name="first" xsi:type="string">global</item>
                </argument>
            </arguments>
        </type>
    ...
    

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM

Tags used