26

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" /> 
5
  • 1
    i hope in ur custom module or code your trying to use Magento\Framework\View\Design\Theme\ResolverInterface in constructor or object manager Commented Nov 24, 2015 at 4:28
  • @PradeepKumar No. I'm not.
    – Filipe Sá
    Commented Nov 24, 2015 at 14:19
  • 3
    clear your cache and the contents of var/generation.
    – Marius
    Commented Nov 24, 2015 at 14:23
  • @Marius as stated in the question, I've already removed the /var/* folder completely.
    – Filipe Sá
    Commented Nov 24, 2015 at 14:28
  • Sorry. I missed that line.
    – Marius
    Commented Nov 24, 2015 at 14:44

13 Answers 13

75

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 (or generated/* in newer versions)
  • Clear var/cache
  • Check if the module generating the error is enabled and enable it (bin/magento module:enable Some_Module) or Enable all Magento modules: bin/magento module:enable --all
  • Compile DI bin/magento setup:di:compile
9
  • 1
    there were so many misleading solutions out there and this worked right away
    – user44406
    Commented Jan 8, 2019 at 8:15
  • 6
    Enable Magento modules: bin/magento module:enable --all - Worked for me
    – Agnes
    Commented Feb 18, 2019 at 12:40
  • 4
    NO! It`s not good practice! bin/magento module:enable --all is like chmod -R 777 :( Commented Dec 5, 2019 at 9:22
  • Worked like a charm. Was using a redis container. using flushall resolved the issue Commented Oct 22, 2020 at 11:40
  • flushing the redis cache solved it, even though that project has not even redis configured. I use redis for another shop though.
    – Black
    Commented Dec 2, 2020 at 14:14
10

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

2
  • 1
    worked for me, specifically var/cache Commented Jul 25, 2016 at 17:46
  • 2
    Thanks redis-cli flushall worked for me. Commented Oct 30, 2019 at 1:17
8

Run following command and check.

rm -rf generated

rm -rf var/*

Worked for me.

3

Clear the cache rm -rf var/cache

If redis enabled, clear redis db using command line:

$> redis-cli
$> flushall
2

This worked for me :

 sudo apt-get install php-intl

 sudo service apache2 reload
2

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 on it, I ended up placing 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. :-)

1

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

1

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.

1

you should also check if the module is not disabled in the config.php

    'Magento_Theme' => 0,
0
php bin/magento c:c
php bin/magento setup:di:compile

will fix your issue

0

Dump composer autoload files:

$ composer dumpautoload

Then:

bin/magento setup:upgrade
bin/magento setup:di:compile
0

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();
0

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>
...

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