{"record":{"id":"abab0d9fa56abaef","repo":"symfony/http-kernel","slug":"controller-s-cannot-be-fetched-from-the-container-because-it","errorCode":null,"errorMessage":"Controller \"%s\" cannot be fetched from the container because it is private. Did you forget to tag the service with \"controller.service_arguments\"?","messagePattern":"Controller \"(.+?)\" cannot be fetched from the container because it is private\\. Did you forget to tag the service with \"controller\\.service_arguments\"\\?","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Controller/ContainerControllerResolver.php","lineNumber":58,"sourceCode":"\n        try {\n            return parent::instantiateController($class);\n        } catch (\\Error $e) {\n        }\n\n        $this->throwExceptionIfControllerWasRemoved($class, $e);\n\n        if ($e instanceof \\ArgumentCountError) {\n            throw new \\InvalidArgumentException(\\sprintf('Controller \"%s\" has required constructor arguments and does not exist in the container. Did you forget to define the controller as a service?', $class), 0, $e);\n        }\n\n        throw new \\InvalidArgumentException(\\sprintf('Controller \"%s\" does neither exist as service nor as class.', $class), 0, $e);\n    }\n\n    private function throwExceptionIfControllerWasRemoved(string $controller, \\Throwable $previous): void\n    {\n        if ($this->container instanceof Container && isset($this->container->getRemovedIds()[$controller])) {\n            throw new \\InvalidArgumentException(\\sprintf('Controller \"%s\" cannot be fetched from the container because it is private. Did you forget to tag the service with \"controller.service_arguments\"?', $controller), 0, $previous);\n        }\n    }\n}\n","sourceCodeStart":40,"sourceCodeEnd":62,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Controller/ContainerControllerResolver.php#L40-L62","documentation":"Symfony's ContainerControllerResolver found a controller id in the compiled container's list of removed (private, unused) service ids. The service was removed at compile time because nothing makes it public/autowired as a controller, so it cannot be fetched at runtime and an InvalidArgumentException is thrown.","triggerScenarios":"Requesting a route whose _controller is a service id (e.g. 'App\\Controller\\FooController') but the service is private and not tagged with controller.service_arguments (or not auto-registered via the _instanceof controller.service_attributes defaults). Also occurs when services.yaml sets 'public: false' with 'autoconfigure: false' or the class lives outside the controllers autoloaded namespace.","commonSituations":"Controller defined manually in services.yaml without the controller.service_arguments tag; services.yaml using 'resource: .' with excluded controller dirs; class outside App\\ namespace not matched by the framework.controller autoconfig; Symfony upgrades where autconfigure behavior changed.","solutions":["Tag the service with controller.service_arguments in services.yaml so it is made public/autowired for controllers","Prefer relying on Symfony's default autoconfiguration: put the class under the controllers namespace or add _instanceof + autoconfigure: true","If not a real controller, fix the route's _controller value to point at the correct class/service id","Pass constructor arguments explicitly in the route defaults if the controller cannot be a service"],"exampleFix":"# before (services.yaml)\nApp\\Controller\\FooController:\n    public: false\n\n// after\nservices:\n    App\\Controller\\FooController:\n        tags: ['controller.service_arguments']","handlingStrategy":"validation","validationCode":"if ($this->container instanceof Container && isset($this->container->getRemovedIds()[$controllerId])) {\n    // controller service is private/removed: fix registration before dispatch\n}","typeGuard":"function isPublicControllerService(ContainerInterface $c, string $id): bool {\n    return !$c instanceof Container || !isset($c->getRemovedIds()[$id]);\n}","tryCatchPattern":"try { $controller = $resolver->getController($request); } catch (\\InvalidArgumentException $e) {\n    // check for 'cannot be fetched from the container because it is private'\n}","preventionTips":["Always tag controller services with controller.service_arguments when defining them manually","Rely on autoconfiguration under the controllers namespace instead of manual service definitions","Run container:debug to verify the controller service is public/resolvable","Keep controllers inside the autoconfigured namespace configured in framework.controller"],"tags":["symfony","dependency-injection","controller","routing"],"backgroundTag":"missing-dependency","analyzedSha":"aa3a39d7286a62cdfea98f0e69c651a3da6e36cf","analyzedAt":"2026-09-13T18:03:36.509Z","contentChangedAt":"2026-09-13T18:03:36.509Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}