symfony/http-kernel · error · InvalidArgumentException
Controller " " cannot be fetched from the container because…
Error message
Controller "%s" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?
What it means
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.
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
Example fix
# before (services.yaml)
App\Controller\FooController:
public: false
// after
services:
App\Controller\FooController:
tags: ['controller.service_arguments'] Defensive patterns
Strategy: validation
Validate before calling
if ($this->container instanceof Container && isset($this->container->getRemovedIds()[$controllerId])) {
// controller service is private/removed: fix registration before dispatch
} Type guard
function isPublicControllerService(ContainerInterface $c, string $id): bool {
return !$c instanceof Container || !isset($c->getRemovedIds()[$id]);
} Try / catch
try { $controller = $resolver->getController($request); } catch (\InvalidArgumentException $e) {
// check for 'cannot be fetched from the container because it is private'
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
Related errors
- Controller " " has required constructor arguments and does…
- Controller " " does neither exist as service nor as class.
- The controller for URI
- Message built by getControllerError(): e.g. Function
- Users will expect the alias of the default extension of a…
AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13).
Data as JSON: /api/errors/abab0d9fa56abaef.
Report an issue: GitHub.
Appendix: source
Thrown at Controller/ContainerControllerResolver.php:58
try {
return parent::instantiateController($class);
} catch (\Error $e) {
}
$this->throwExceptionIfControllerWasRemoved($class, $e);
if ($e instanceof \ArgumentCountError) {
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);
}
throw new \InvalidArgumentException(\sprintf('Controller "%s" does neither exist as service nor as class.', $class), 0, $e);
}
private function throwExceptionIfControllerWasRemoved(string $controller, \Throwable $previous): void
{
if ($this->container instanceof Container && isset($this->container->getRemovedIds()[$controller])) {
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);
}
}
}
View on GitHub (pinned to aa3a39d728)