{"record":{"id":"3d4c588c664dece6","repo":"symfony/http-kernel","slug":"controller-s-has-required-constructor-arguments-and-does-not","errorCode":null,"errorMessage":"Controller \"%s\" has required constructor arguments and does not exist in the container. Did you forget to define the controller as a service?","messagePattern":"Controller \"(.+?)\" has required constructor arguments and does not exist in the container\\. Did you forget to define the controller as a service\\?","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Controller/ContainerControllerResolver.php","lineNumber":49,"sourceCode":"    }\n\n    protected function instantiateController(string $class): object\n    {\n        $class = ltrim($class, '\\\\');\n\n        if ($this->container->has($class)) {\n            return $this->container->get($class);\n        }\n\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":31,"sourceCodeEnd":62,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Controller/ContainerControllerResolver.php#L31-L62","documentation":"ContainerControllerResolver falls back to instantiating the controller class directly when it is not in the container. If that constructor call fails with an ArgumentCountError (required constructor arguments cannot be satisfied), Symfony rethrows it as this InvalidArgumentException, indicating the controller should be registered as a service.","triggerScenarios":"A controller class with constructor dependencies that is neither autoconfigured as a service (controller.service_arguments) nor registered in the container, then invoked as Class::method.","commonSituations":"Forgetting the #[Autoconfigure]/autowire config, missing services.yaml controller resource registration, or after switching from attribute-less controllers to injected services.","solutions":["Register the controller as a service (autowire/autoconfigure or explicit definition)","Ensure the services.yaml controller resource loads the class","Add controller.service_arguments tag so the container resolves it","Remove required constructor deps if the controller should be stateless/instantiable directly"],"exampleFix":"// services.yaml — before\n# controller not registered\n// after\nApp\\Controller\\ReportController:\n    autowire: true\n    autoconfigure: true","handlingStrategy":"validation","validationCode":"if (!empty((new \\ReflectionClass($ctrl))->getConstructor()?->getParameters()) && !$container->has($ctrl)) { throw new \\RuntimeException('register controller as service'); }","typeGuard":"$container->has($controllerClass)","tryCatchPattern":"try { $response = $kernel->handle($request); } catch (\\InvalidArgumentException $e) { if (str_contains($e->getMessage(), 'required constructor arguments')) { /* register service */ } throw $e; }","preventionTips":["Enable autowire/autoconfigure for controllers via services.yaml","Tag controllers with controller.service_arguments","Smoke-test all routes in CI"],"tags":["symfony","dependency-injection","controller","autowiring"],"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"}