0

I get below error after I do bin/magento setup:upgrade on my local env. The only workaround I got so far is to run bin/magento setup:di:complile. After running di compile the error is gone unit I run setup:upgrade again. I am in developer mode.

What is the root problem, and how can I solve it?

1 exception(s): Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Magento\Framework\Config\Dom, Magento\Framework\Config\Dom::__construct(): Argument #2 ($validationState) must be of type Magento\Framework\Config\ValidationStateInterface, null given, called in /data/web/application/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121

1 exception(s):
Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Magento\Framework\Config\Dom, Magento\Framework\Config\Dom::__construct(): Argument #2 ($validationState) must be of type Magento\Framework\Config\ValidationStateInterface, null given, called in /data/web/application/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121

Exception #0 (Magento\Framework\Exception\RuntimeException): Type Error occurred when creating object: Magento\Framework\Config\Dom, Magento\Framework\Config\Dom::__construct(): Argument #2 ($validationState) must be of type Magento\Framework\Config\ValidationStateInterface, null given, called in /data/web/application/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121
<pre>#1 Magento\Framework\ObjectManager\Factory\Dynamic\Developer->create() called at [vendor/magento/framework/ObjectManager/ObjectManager.php:56]
#2 Magento\Framework\ObjectManager\ObjectManager->create() called at [vendor/magento/framework/Config/DomFactory.php:43]
#3 Magento\Framework\Config\DomFactory->createDom() called at [vendor/magento/framework/View/Model/Layout/Update/Validator.php:141]
#4 Magento\Framework\View\Model\Layout\Update\Validator->isValid() called at [vendor/magento/framework/View/Model/Layout/Merge.php:524]
#5 Magento\Framework\View\Model\Layout\Merge->_validateMergedLayout() called at [vendor/magento/framework/View/Model/Layout/Merge.php:500]
#6 Magento\Framework\View\Model\Layout\Merge->load() called at [generated/code/Hyva/Theme/Framework/View/Model/Layout/Merge/Interceptor.php:149]
#7 Hyva\Theme\Framework\View\Model\Layout\Merge\Interceptor->load() called at [vendor/magento/framework/View/Layout/Builder.php:86]
#8 Magento\Framework\View\Layout\Builder->loadLayoutUpdates() called at [vendor/magento/framework/View/Layout/Builder.php:63]
#9 Magento\Framework\View\Layout\Builder->build() called at [vendor/magento/framework/View/Page/Config.php:227]
#10 Magento\Framework\View\Page\Config->build() called at [vendor/magento/framework/View/Page/Config.php:591]
#11 Magento\Framework\View\Page\Config->getElementAttribute() called at [generated/code/Magento/Framework/View/Page/Config/Interceptor.php:248]
#12 Magento\Framework\View\Page\Config\Interceptor->getElementAttribute() called at [vendor/magento/framework/View/Page/Config.php:549]
#13 Magento\Framework\View\Page\Config->addBodyClass() called at [generated/code/Magento/Framework/View/Page/Config/Interceptor.php:230]
#14 Magento\Framework\View\Page\Config\Interceptor->addBodyClass() called at [vendor/magento/module-catalog/Controller/Category/View.php:246]
#15 Magento\Catalog\Controller\Category\View->execute() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#16 Magento\Catalog\Controller\Category\View\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#17 Magento\Catalog\Controller\Category\View\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#18 Magento\Catalog\Controller\Category\View\Interceptor->___callPlugins() called at [generated/code/Magento/Catalog/Controller/Category/View/Interceptor.php:23]
#19 Magento\Catalog\Controller\Category\View\Interceptor->execute() called at [vendor/magento/framework/App/Action/Action.php:111]
#20 Magento\Framework\App\Action\Action->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#21 Magento\Catalog\Controller\Category\View\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#22 Magento\Catalog\Controller\Category\View\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#23 Magento\Catalog\Controller\Category\View\Interceptor->___callPlugins() called at [generated/code/Magento/Catalog/Controller/Category/View/Interceptor.php:32]
#24 Magento\Catalog\Controller\Category\View\Interceptor->dispatch() called at [vendor/magento/framework/App/FrontController.php:245]
#25 Magento\Framework\App\FrontController->getActionResponse() called at [vendor/magento/framework/App/FrontController.php:212]
#26 Magento\Framework\App\FrontController->processRequest() called at [vendor/magento/framework/App/FrontController.php:147]
#27 Magento\Framework\App\FrontController->dispatch() called at [vendor/magento/framework/Interception/Interceptor.php:58]
#28 Magento\Framework\App\FrontController\Interceptor->___callParent() called at [vendor/magento/framework/Interception/Interceptor.php:138]
#29 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-store/App/FrontController/Plugin/RequestPreprocessor.php:99]
#30 Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#31 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/amasty/aminvisiblecaptcha/Plugin/Framework/App/FrontControllerInterface/ValidateCaptcha.php:124]
#32 Amasty\InvisibleCaptcha\Plugin\Framework\App\FrontControllerInterface\ValidateCaptcha->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#33 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/module-page-cache/Model/App/FrontController/BuiltinPlugin.php:75]
#34 Magento\PageCache\Model\App\FrontController\BuiltinPlugin->aroundDispatch() called at [vendor/magento/framework/Interception/Interceptor.php:135]
#35 Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}() called at [vendor/magento/framework/Interception/Interceptor.php:153]
#36 Magento\Framework\App\FrontController\Interceptor->___callPlugins() called at [generated/code/Magento/Framework/App/FrontController/Interceptor.php:23]
#37 Magento\Framework\App\FrontController\Interceptor->dispatch() called at [vendor/magento/framework/App/Http.php:116]
#38 Magento\Framework\App\Http->launch() called at [generated/code/Magento/Framework/App/Http/Interceptor.php:23]
#39 Magento\Framework\App\Http\Interceptor->launch() called at [vendor/magento/framework/App/Bootstrap.php:264]
#40 Magento\Framework\App\Bootstrap->run() called at [pub/index.php:30]
</pre>

3 Answers 3

1

Instead of running the command. Please solve the error that causes the root issue. It seems you have a Type Error Occurred When creating an object I Dom object in the constructor of the class.

If your Magento 2 version is not the latest version so it means the issue is in your custom module is not Magento 2.4.* compatible.

You should update your custom modules to the updated version.

Another way around to fix this possible solutions are:

  • Run the setup upgrade again and then compile your code.
  • Find out which class is not compatible with your class that is causing the issue:

Open the class data/web/application/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 121, Add the below line of code, and it will give you the Class name and method name.

if($dataType === null || empty($dataType)){echo $serviceClassName.'<>'.$serviceMethodName . PHP_EOL;}

Putting it here in case someone needs it.

  • Check the PHP version is compatible with your Magento version.
  • This is the error sometimes when the constructor is called with a missing parameter.
  • Quick fix if nothing works try to setup an empty array for the required null parameter and see what happens after compilation.
  • Perhaps as per the M2.4.6, optional parameters come after the mandatory.

Thanks

0

Can please run below commands and then run compile command

chmod -R 777 var/ generated/ pub/
rm -rf var/cache/* var/page_cache/* var/view_preprocessed/* generated/*
chmod -R 777 var/ generated/ pub/

compile command

php bin/magento setup:di:complile
4
  • Thanks. What is the idea behind this? In developer mode setup:di:compile shouldn't be necessary at all....
    – Akif
    Commented Jul 14, 2023 at 9:19
  • Clear the generated folder and re-generated the classess
    – MP Raj
    Commented Jul 14, 2023 at 9:39
  • Doesn't fix the issue. It still remains.
    – Akif
    Commented Jul 14, 2023 at 9:46
  • magento.stackexchange.com/questions/348000/…
    – MP Raj
    Commented Jul 14, 2023 at 9:53
0

It seems there was a module active which was doing things with XML/XSD. I think it was a fix for a pre version of 2.4.5. After upgrade, this module was not necessary, but it was still in the repo. Deleting it fixed the issue.

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.