symfony/routing · error · InvalidArgumentException
Invalid resource " " passed to the route loader: use the…
Error message
Invalid resource "%s" passed to the %s route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.
What it means
ObjectLoader::load() expects a routing resource string identifying an object method in the form 'object_id::method', or just 'object_id' when the service class has an __invoke method. Any resource string not matching this pattern is rejected with InvalidArgumentException before the loader even resolves the object.
Solutions
- Use a service id followed by :: and the method name, e.g. 'app.route_loader::loadRoutes'
- If using __invoke, pass only the service id, e.g. 'app.route_loader'
- Check the resource string for typos — stray '::', file paths, or FQCNs with backslashes are not accepted; register the class as a service and use its id
Example fix
# before (config/packages/routing.yaml)
app_routes:
resource: 'App\Routing\RoutesLoader::load'
type: service
# after
app_routes:
resource: 'app.routing.routes_loader::load'
type: service Defensive patterns
Strategy: validation
Validate before calling
if (!preg_match('/^[^:]+(?:::(?:[^:]+))?$/', $resource)) {
throw new \InvalidArgumentException('Resource must be "object_id::method" or "object_id".');
} Type guard
function isValidObjectResource(string $resource): bool { return preg_match('/^[^:]+(?:::(?:[^:]+))?$/', $resource) === 1; } Try / catch
try { $collection = $loader->load($resource, 'service'); } catch (\InvalidArgumentException $e) { /* fix resource format to object_id::method */ } Prevention
- Use service ids, never FQCNs or file paths, in the resource string
- Remember the separator is exactly '::'
- Only omit ::method when the class has __invoke
When it happens
Trigger: Passing a malformed resource to the object route loader, e.g. containing extra colons ('service::method::extra'), absolute file paths, class::staticMethod (static call syntax is fine per regex but plain strings with slashes/URLs are not), or an empty string.
Common situations: Configuring type: service imports with a wrong resource syntax; pasting a file path or controller action string ('App\\Controller::index' with a namespace — namespaces contain backslashes which fail the regex) instead of a service id.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Method " " not found on " " when importing routing resource…
- Parameter " " for route " " must match " " (" " given) to…
- Parameters for route
- Route aliases cannot be used on non-invokable class
- The " ()" method must not be called.
AI-assisted analysis of symfony/routing@83fa223250 (2026-09-14).
Data as JSON: /api/errors/97a7dde47cc34a3d.
Report an issue: GitHub.
Appendix: source
Thrown at Loader/ObjectLoader.php:39
* @author Ryan Weaver <ryan@knpuniversity.com>
*/
abstract class ObjectLoader extends Loader
{
/**
* Returns the object that the method will be called on to load routes.
*
* For example, if your application uses a service container,
* the $id may be a service id.
*/
abstract protected function getObject(string $id): object;
/**
* Calls the object method that will load the routes.
*/
public function load(mixed $resource, ?string $type = null): RouteCollection
{
if (!preg_match('/^[^\:]+(?:::(?:[^\:]+))?$/', $resource)) {
throw new \InvalidArgumentException(\sprintf('Invalid resource "%s" passed to the %s route loader: use the format "object_id::method" or "object_id" if your object class has an "__invoke" method.', $resource, \is_string($type) ? '"'.$type.'"' : 'object'));
}
$parts = explode('::', $resource);
$method = $parts[1] ?? '__invoke';
$loaderObject = $this->getObject($parts[0]);
if (!\is_callable([$loaderObject, $method])) {
throw new \BadMethodCallException(\sprintf('Method "%s" not found on "%s" when importing routing resource "%s".', $method, get_debug_type($loaderObject), $resource));
}
$routeCollection = $loaderObject->$method($this, $this->env);
if (!$routeCollection instanceof RouteCollection) {
$type = get_debug_type($routeCollection);
throw new \LogicException(\sprintf('The "%s::%s()" method must return a RouteCollection: "%s" returned.', get_debug_type($loaderObject), $method, $type));
}View on GitHub (pinned to 83fa223250)