{"record":{"id":"41f9258d32f44316","repo":"symfony/http-kernel","slug":"controller-s-does-neither-exist-as-service-nor-as-class","errorCode":null,"errorMessage":"Controller \"%s\" does neither exist as service nor as class.","messagePattern":"Controller \"(.+?)\" does neither exist as service nor as class\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Controller/ContainerControllerResolver.php","lineNumber":52,"sourceCode":"    {\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":34,"sourceCodeEnd":62,"githubUrl":"https://github.com/symfony/http-kernel/blob/aa3a39d7286a62cdfea98f0e69c651a3da6e36cf/Controller/ContainerControllerResolver.php#L34-L62","documentation":"This is a fallback validation error in the controller resolver: the requested controller string was first looked up as a container service (container->has failed), then instantiation as a plain class was attempted and threw an \\Error that was not attributable to a removed controller or to required constructor arguments. The controller reference is unresolvable — typically a typo in the service id/class name, a class that cannot be autoloaded, or a controller never registered as a service.","triggerScenarios":"Referencing a controller string like App\\Controller\\MissingController::index (typo, wrong namespace, class not autoloaded) or a service id that does not exist, e.g. in a route _controller.","commonSituations":"Typos in route _controller values, deleted/renamed controller classes with stale routes, composer autoload not regenerated, or referring to a private/removed service id.","solutions":["Fix the class name/namespace in the route's _controller value","Verify the class exists and composer dump-autoload has been run","If it should be a service, register it with the correct id","Check throwExceptionIfControllerWasRemoved hints — the id may be a removed private service"],"exampleFix":"// before\n#[Route('/x', name: 'x', controller: 'App\\Controller\\ReportControler::index')]\n// after\n#[Route('/x', name: 'x', controller: 'App\\Controller\\ReportController::index')]","handlingStrategy":"validation","validationCode":"if (!class_exists($class) && !$container->has($id)) { throw new \\RuntimeException(\"controller {$class} not found\"); }","typeGuard":"class_exists($controllerClass) || $container->has($controllerId)","tryCatchPattern":"try { $response = $kernel->handle($request); } catch (\\InvalidArgumentException $e) { if (str_contains($e->getMessage(), 'does neither exist as service nor as class')) { /* fix _controller reference */ } throw $e; }","preventionTips":["Validate route _controller values in a CI route smoke test","Run composer dump-autoload after adding classes","Grep routes for controllers after renames/deletions"],"tags":["symfony","routing","controller","class-not-found"],"backgroundTag":"class-not-found","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"}