symfony/http-kernel · error · InvalidArgumentException

Controller " " has required constructor arguments and does…

Error message

Controller "%s" has required constructor arguments and does not exist in the container. Did you forget to define the controller as a service?

What it means

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.

Solutions

  1. Register the controller as a service (autowire/autoconfigure or explicit definition)
  2. Ensure the services.yaml controller resource loads the class
  3. Add controller.service_arguments tag so the container resolves it
  4. Remove required constructor deps if the controller should be stateless/instantiable directly

Example fix

// services.yaml — before
# controller not registered
// after
App\Controller\ReportController:
    autowire: true
    autoconfigure: true
Defensive patterns

Strategy: validation

Validate before calling

if (!empty((new \ReflectionClass($ctrl))->getConstructor()?->getParameters()) && !$container->has($ctrl)) { throw new \RuntimeException('register controller as service'); }

Type guard

$container->has($controllerClass)

Try / catch

try { $response = $kernel->handle($request); } catch (\InvalidArgumentException $e) { if (str_contains($e->getMessage(), 'required constructor arguments')) { /* register service */ } throw $e; }

Prevention

When it happens

Trigger: 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.

Common situations: Forgetting the #[Autoconfigure]/autowire config, missing services.yaml controller resource registration, or after switching from attribute-less controllers to injected services.

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


AI-assisted analysis of symfony/http-kernel@aa3a39d728 (2026-09-13). Data as JSON: /api/errors/3d4c588c664dece6. Report an issue: GitHub.

Appendix: source

Thrown at Controller/ContainerControllerResolver.php:49

    }

    protected function instantiateController(string $class): object
    {
        $class = ltrim($class, '\\');

        if ($this->container->has($class)) {
            return $this->container->get($class);
        }

        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)