Magento – Fatal error after Magento installation ‘undefined method ProductExtension::setStockItem()’

code generationextension-attributesinstallationmagento2

When I run Magento I get

PHP Fatal error: Call to undefined method
Magento\Catalog\Api\Data\ProductExtension::setStockItem() in
/var/www/magento/vendor/magento/module-catalog-inventory/Model/Plugin/AfterProductLoad.php
on line 47

Please help

Best Answer

The problem seems to be that ProductExtension is not generated (this is auto-generated class).

If running Magento in production or default mode, code generation on-fly is disabled and you need to run compiler after installation, execute <project_root>/bin/magento setup:di:compile as described in Magento dev docs.

If running Magento in developer mode, make sure var/generation directory is writable.