I can't install any custom modules. When I do this, I get error in admin panel in Magento 2.2.0.
I installed it on my PC on Windows 7 and XAMPP 7.1.9 (which contains PHP 7.1.9, Apache 2.4.27, MariaDB 10.1.26). But then I tried it also on Magento optimized hosting from Nexcess and I get exactly the same error.
D:\xampp\htdocs\my\ folderD:\xampp\htdocs\my\app\code\Company\Simple\ folder (full code of this module is presented at the end of my post)php magento module:enable Company_Simplephp magento setup:upgradephp magento setup:di:compileThe "Dashboard" page in Magento admin panel should work normally.
The page is blank and the following error is displayed:
Fatal error: Uncaught Error: Call to a member function setActive() on boolean in D:\xampp\htdocs\my\vendor\magentomodule-backend\Model\View\Result\Page.php:27 Stack trace: #0 D:\xampp\htdocs\my\vendor\magentomodule-backend\Controller\Adminhtml\Dashboard\Index.php(35): Magento\Backend\Model\View\Result\Page->setActiveMenu('Magento_Backend...') #1 D:\xampp\htdocs\my\vendor\magento\framework\App\Action\Action.php(107): Magento\Backend\Controller\Adminhtml\Dashboard\Index->execute() #2 D:\xampp\htdocs\my\vendor\magentomodule-backend\App\AbstractAction.php(229): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http)) #3 D:\xampp\htdocs\my\vendor\magento\framework\App\FrontController.php(55): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framework\App\Request\Http)) #4 D:\xampp\htdocs\my\vendor\magento\framework\App\Http.php(135): Magento\Framework\App\FrontController->dispatch(Object(Magento\Framework\App\Request\Http in D:\xampp\htdocs\my\vendor\magentomodule-backend\Model\View\Result\Page.php on line 27
_Module manager works fine_
So I can't display any page in admin panel, but when I manually type in the address of Module Manager in my browser (http://localhost/my/setup/#/module-grid), the Module Manager page is displayed correctly and my module Company_Simple is listed in the table of installed modules:
company/module-simple | Company_Simple | 2.0.0 | Company
_How to make the admin work correctly again_
I noticed that if I delete this file:
generated/metadata/global.php
the admin panel starts to work correctly again.
Below is the full code of my test module. It is a minimal module for testing. Here's the files structure:
Here's the code of each file:
composer.json:
{
"name": "company/module-simple",
"description": "",
"require": {
"php": "~5.6.0|~7.0.0|~7.1.0"
},
"type": "magento2-module",
"version": "2.0.0",
"license": [
"Proprietary"
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Company\\Simple\\": ""
}
}
}
registration.php:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Company_Simple',
__DIR__
);
etc/module.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Company_Simple" setup_version="2.0.0" />
</config>
Helper/Data.php:
<?php
namespace Company\Simple\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
class Data extends AbstractHelper
{
/**
* Test method
*
* @return string
*/
public function doSomething()
{
return "Do something.";
}
}
From \Magento\Backend\Model\View\Result\Page::setActiveMenu it looks like somehow menu block is missing in layout. Needs to be debugged further on your environment.
What could cause that? It's clean installation.
Debugger will show. If you tried to clean everything up (caches, var/*, generated/*) it's hard to guess what else may be broken.
I'm not sure how to debug this further. That part of vendor\magento\module-backend\Model\View\Result\Page.php looks like this:
public function setActiveMenu($itemId)
{
/** @var $menuBlock \Magento\Backend\Block\Menu */
$menuBlock = $this->layout->getBlock('menu');
$menuBlock->setActive($itemId);
$parents = $menuBlock->getMenuModel()->getParentItems($itemId);
foreach ($parents as $item) {
/** @var $item \Magento\Backend\Model\Menu\Item */
$this->getConfig()->getTitle()->prepend($item->getTitle());
}
return $this;
}
Error indicates that $this->layout->getBlock('menu') returns boolean instead of object. What can cause that? And what exactly is that menu block? My module doesn't make any layout changes and doesn't have any layout files. I didn't make any customizations (and didn't install any other extensions) so I didn't remove any blocks, especially not menu.
You need to enable xdebug and trace into $this->layout->getBlock('menu') call. It returns false when no block found in layout with such name.
@gitpol, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.2.0
I traced into $this->layout->getBlock('menu') with xdebug. The layout is being built but I'm not sure where to look, a lot is happening there and I don't know the process of building layout. For example, in vendor\magento\framework\View\Layout\Builder.php:
public function build()
{
if (!$this->isBuilt) {
$this->isBuilt = true;
$this->loadLayoutUpdates();
$this->generateLayoutXml();
$this->generateLayoutBlocks();
}
return $this->layout;
}
when I step into $this->generateLayoutXml() there is the following method executed in vendor\magento\framework\View\Layout.php:
public function generateXml()
{
$xml = $this->getUpdate()->asSimplexml();
$this->setXml($xml);
$this->structure->importElements([]);
return $this;
}
When I dump the $xml object I see that there's no menu block in the layout XML (see the content of this object: https://pastebin.com/qYrxhA2f).
But if I remove my custom module (or when I delete this file generated/metadata/global.php) the $xml object contains the menu block (see the content of this object: https://pastebin.com/JrpYtnj2).
What exactly is that menu block? The main admin menu which is displayed at the left side? If yes, then what could cause that it's not included in the layout blocks when my module is enabled? Where should I search? I'm totally lost.
But if I remove my custom module
Did you provide a full module code? You may want to debug a merging stage to see how declaration from your custom module affects resulting layout XML.
Yes, in my first post I provided full code of my simple module. It doesn't contain any layout XML.
I have installed a module on M 2.2.0 that was working fine on M 2.1.x, and got the same error
Fatal error: Uncaught Error: Call to a member function setActive() on boolean in vendor\magentomodule-backend\Model\View\Result\Page.php:27 Stack trace:
the error was gone when I have removed generated/metadata/global.php
@ayasoftware, I had the same problem. So I created a simple minimal module for testing but it gives exactly the same error. Please try to use my test module to see if you will have the same results. You can find it here: https://github.com/gitpol/test-module-company-simple Install it in app/code/Company/Simple in the root directory of your Magento.
@magento-engcom-team, please reopen the issue if you can.
@gitpol , We have facing the same issue in Magento 2.2.0. So, if you resolve the issue at your end then share the solution to fix.
try deleting the directories in generated folder from magento root directory.
Try deleting generated\metadata in magento2 root directory.
Did nobody find a reason for this? I've installed a bought extension the other day and the same error is happening in production mode. Developer mode works fine. And removing the global.php fixes it.
I've had an extensive debugging session and I had some insights into the issue. But no solution.
The issue seems to be that the backend theme is not properly created when this issue is happening.
The trace differs early on and Magento tries to create the backend theme a different way with or without the global.php.
I think the key is this file:
vendor\magentomodule-theme\Model\View\Design.php
When the issue is happening Magento never "sets" the theme. It just gets it at some point and because it's not there it's created on the fly, which creates a faulty theme.
public function getDesignTheme()
{
if ($this->_theme === null) {
$this->_theme = $this->_themeFactory->create();
}
return $this->_theme;
}
When calling getDesignTheme without a theme set before it creates a theme that just consists of one field "type" with the value of 1.
When the issue is not happening the theme is created differently by setting it. In this function:
public function setDesignTheme($theme, $area = null)
{
if ($area) {
$this->setArea($area);
} else {
$area = $this->getArea();
}
if ($theme instanceof \Magento\Framework\View\Design\ThemeInterface) {
$this->_theme = $theme;
} else {
$this->_theme = $this->_flyweightFactory->create($theme, $area);
}
return $this;
}
The code runs through the "else" part of the second if condition. That creates a proper theme.
It seems like none of the plugins that are in place before and during theme creation are called when the issue is happening. As I mentioned the trace differs in both cases:
Faulty trace:

Working trace:

And I've noticed that both, me and the one that opened this issue, are running Magento on "xampp" which means Windows. Maybe that's got something to do with it.
I've tested again on an Ubuntu setup with the same Magento and Extension Version and there are no problems. I think that says it all. It's some Windows/Xampp kind of issue I won't bother with further.
@C4rter The issue doesn't need to be caused by Windows/Xampp. Maybe there's just some kind of a bug in Magento which reveals itself only on Windows/Xampp (e.g. because of how Windows handles file permissions, or something like that).
Same problem here. I'm also running on Windows Xammp. Did you find any solution for this error?
Are you running XAMPP in administration mode. Because I had the same issue and solved it by re running XAMPP as administrator, restart processes and redeploy static content.
I'm experiencing the exact same problem.
Using WampServer (on Windows 10) Version 3.1.3 (64bit) with PHP 7.1.16.
Running Magento version 2.2.3
@magento-engcom-team
Is Magento even made for Windows? 馃槙
@C4rter
I would like to emphasize that, as I mentioned earlier, I also tested it on Magento optimized hosting from Nexcess and I got exactly the same error. So it's not a Windows/XAMPP specific issue.
same issue here,
Windows 10
XAMPP
Magento 2
I had a similar issue just and was down to a carrage return in a layout file
By chaning from
<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
to
<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
The error dissapeared very strange but i have seen this on a number of occasions not only this issue but generation issues
I have the same issue. anyone has a solution yet? above solutions not working for me.
Can u post the file it associates with or the error
I created the custom module and it gives me the error when I try to add the new entry from admin grid.
Fatal error: Uncaught Error: Call to a member function setActive() on boolean in /home/www/jambiyo.com/vendor/magento/module-backend/Model/View/Result/Page.php:27 Stack trace: #0 /home/www/jambiyo.com/app/code/MyModule/StoreLocator/Controller/Adminhtml/Storelocator/Edit.php(53): Magento\Backend\Model\View\Result\Page->setActiveMenu('www_StoreL...') #1 /home/www/jambiyo.com/app/code/MyModule/StoreLocator/Controller/Adminhtml/Storelocator/Edit.php(89): MyModule\StoreLocator\Controller\Adminhtmlstorelocator\Edit->_initAction() #2 /home/MyModule/jambiyo.com/vendor/magento/framework/App/Action/Action.php(107): MyModule\StoreLocator\Controller\Adminhtmlstorelocator\Edit->execute() #3 /home/MyModule/jambiyo.com/vendor/magento/module-backend/App/AbstractAction.php(229): Magento\Framework\App\Action\Action->dispatch(Object(Magento\Framework\App\Request\Http)) #4 /home/MyModule/jambiyo.com/vendor/magento/framework/App/FrontController.php(55): Magento\Backend\App\AbstractAction->dispatch(Object(Magento\Framewor in /home/MyModule/jambiyo.com/vendor/magento/module-backend/Model/View/Result/Page.php on line 27
Anyway to see the layouts anything xml in module
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="storelocator_storelocator_edit"/>
<body/>
</page>
above is code from storelocator_storelocator_new.xml
Can u include a screenshot in its native formatting as this doesn't help
I had a similar issue just and was down to a carrage return in a layout file
By chaning from
<?xml version="1.0" ?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">to
<?xml version="1.0" ?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">The error dissapeared very strange but i have seen this on a number of occasions not only this issue but generation issues
I was experiencing this issue, and was even able to solve it by deleting (read: re-naming) generated/metadata/global.php also worked for a little while, but the issue did eventually did appear again, on another admin page.
My store is on a linux server, so I wasn't buying the xampp/windows theory. However, I do develop on windows using PHPstorm. And I know that PHP storm will sometimes break lines to "clean up" code, so that seemed like a more plausible theory.
I used a regex search in app/code/ to find any of my extensions that matched http://www.w3.org/2001/XMLSchema-instance"\n, and discovered there was a layout XML for a module that related to what page I was getting the error. I removed the newline, and everything was back to normal.
I then built a regex to see if there are other XML layout files that have this newline:
find . -path "*/layout/*.xml" -exec grep -lir "http://www.w3.org/2001/XMLSchema-instance\"" {} +
and it turned out there are a lot of core files that have this, which might explain why some people have this issue on clean installs. What I can't explain is why it isn't more widespread, or why it is even an issue.
More testing is necessary.
For anyone experiencing this issue as I was I had the generated folder as a symlink - in hindsight a bad idea as it served no purpose.
Anyway, removing the symlink and creating a standard directory and running compilation resolved the issue and everything started working as normal.
Has anyone found a permanent solution of this issue? I am facing this issue randomly in Magento 2.3.1 EE version.
I had the problem with setActiveMenu. Everytime I visited a specific Page/Route in the Backend, the error occurred.
The trigger for this bug (in my case) was a wrong namespace in the controller/action for this page.
Instead ob My\Namespace\Controller\Adminhtml\... the namespace was my\Namespace\Controller\Adminhtml\....
This seems to be no prolem at all in developer mode, but breaks thing in production mode with generated/metadata/global.php in place