I've seen all the posts about this subject but nothing has helped me. I think my problem is slightly different. I use FOSUser bundle on a Symfony 4 project. When I access my website I get this error:
Argument 3 passed to FOS\UserBundle\Doctrine\UserManager::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, instance of ContainerVxxTSSB\EntityManager_9a5be93 given, called in C:\Users\xxx\Documents\Dev\project\var\cache\dev\ContainerVxxTSSB\srcApp_KernelDevDebugContainer.php on line 1885
I don't know where the error is from, since it indicates a file in the cache. I tried deleting the var folder, but still the same error. The thing that I don't understand is that the error says that I give an instance of "ContainerVxxTSSB\EntityManager_9a5be93" but I don't see how it could be possible. I don't even know where to search to resolve this.
services.yaml
user_factory:
class: App\Security\UserFactory
arguments: ["@fos_user.user_manager", "@doctrine.orm.entity_manager", "%kernel.logs_dir%"]
UserFactory.php:
use App\Entity\User;
use FOS\UserBundle\Doctrine\UserManager;
use Hslavich\OneloginSamlBundle\Security\Authentication\Token\SamlTokenInterface;
use Hslavich\OneloginSamlBundle\Security\User\SamlUserFactoryInterface;
class UserFactory implements SamlUserFactoryInterface
{
private $userManager;
private $entityManager;
private $logs_dir;
public function __construct(UserManager $userManager, $entityManager, $logs_dir)
{
$this->userManager = $userManager;
$this->entityManager = $entityManager;
$this->logs_dir = $logs_dir;
}
and then in UserManager.php in the vendor folder:
/**
* Constructor.
*
* @param PasswordUpdaterInterface $passwordUpdater
* @param CanonicalFieldsUpdater $canonicalFieldsUpdater
* @param ObjectManager $om
* @param string $class
*/
public function __construct(PasswordUpdaterInterface $passwordUpdater, CanonicalFieldsUpdater $canonicalFieldsUpdater, ObjectManager $om, $class)
{
parent::__construct($passwordUpdater, $canonicalFieldsUpdater);
$this->objectManager = $om;
$this->class = $class;
}
Edit: The doctrine info in the composer.json
"doctrine/annotations": "^1.0",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "^2.8",
The line indicated by the error:
return $this->services['fos_user.user_manager'] = new \FOS\UserBundle\Doctrine\UserManager(($this->privates['fos_user.util.password_updater'] ?? $this->getFosUser_Util_PasswordUpdaterService()), ($this->privates['fos_user.util.canonical_fields_updater'] ?? $this->getFosUser_Util_CanonicalFieldsUpdaterService()), ($this->services['doctrine'] ?? $this->getDoctrineService())->getManager(NULL), 'App\\Entity\\User');
To create the project I did:
composer create-project symfony/website-skeleton:"^4.4" project_name
And then to add the bundle
composer require friendsofsymfony/user-bundle
I don't remember getting an error
EDIT 2: When I want to clear cache with this command:
php bin/console clear:cache
I get this error:
TypeError {#742
#message: "Argument 3 passed to FOS\UserBundle\Doctrine\UserManager::__construct() must be an instance of Doctrine\Common\Persistence\ObjectManager, instance of ContainerXNABQPE\EntityManager_9a5be93 given, called in C:\Users\xxx\Documents\Dev\test\var\cache\dev\ContainerXNABQPE\srcApp_KernelDevDebugContainer.php on line 1416"
#code: 0
#file: "C:\Users\xxx\Documents\Dev\test\vendor\friendsofsymfony\user-bundle\Doctrine\UserManager.php"
#line: 41
trace: {
C:\Users\xxx\Documents\Dev\test\vendor\friendsofsymfony\user-bundle\Doctrine\UserManager.php:41 { …}
C:\Users\xxx\Documents\Dev\test\var\cache\dev\ContainerXNABQPE\srcApp_KernelDevDebugContainer.php:1416 {
ContainerXNABQPE\srcApp_KernelDevDebugContainer->getFosUser_UserManagerService()
›
› return $this->services['fos_user.user_manager'] = new \FOS\UserBundle\Doctrine\UserManager(($this->privates['fos_user.util.password_updater'] ?? $this->getFosUser_Util_PasswordUpdaterService()), ($this->privates['fos_use
r.util.canonical_fields_updater'] ?? $this->getFosUser_Util_CanonicalFieldsUpdaterService()), ($this->services['doctrine'] ?? $this->getDoctrineService())->getManager(NULL), 'App\\Entity\\User');
› }
arguments: {
$passwordUpdater: FOS\UserBundle\Util\PasswordUpdater {#739 …}
$canonicalFieldsUpdater: FOS\UserBundle\Util\CanonicalFieldsUpdater {#741 …}
$om: ContainerXNABQPE\EntityManager_9a5be93 {#647 …}
$class: "App\Entity\User"
}
}
C:\Users\xxx\Documents\Dev\test\var\cache\dev\ContainerXNABQPE\srcApp_KernelDevDebugContainer.php:4625 { …}
C:\Users\xxx\Documents\Dev\test\var\cache\dev\ContainerXNABQPE\srcApp_KernelDevDebugContainer.php:4388 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\dependency-injection\Container.php:450 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\dependency-injection\Argument\ServiceLocator.php:40 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\CommandLoader\ContainerCommandLoader.php:45 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:548 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:750 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\framework-bundle\Console\Application.php:143 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:561 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:587 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:657 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\framework-bundle\Console\Application.php:117 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:237 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\framework-bundle\Console\Application.php:83 { …}
C:\Users\xxx\Documents\Dev\test\vendor\symfony\console\Application.php:149 { …}
C:\Users\xxx\Documents\Dev\test\bin\console:42 { …}
}
}
can you try the following:
?