{"record":{"id":"97a7dde47cc34a3d","repo":"symfony/routing","slug":"invalid-resource-s-passed-to-the-s-route-loader-use-the","errorCode":null,"errorMessage":"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.","messagePattern":"Invalid resource \"(.+?)\" passed to the (.+?) route loader: use the format \"object_id::method\" or \"object_id\" if your object class has an \"__invoke\" method\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"Loader/ObjectLoader.php","lineNumber":39,"sourceCode":" * @author Ryan Weaver <ryan@knpuniversity.com>\n */\nabstract class ObjectLoader extends Loader\n{\n    /**\n     * Returns the object that the method will be called on to load routes.\n     *\n     * For example, if your application uses a service container,\n     * the $id may be a service id.\n     */\n    abstract protected function getObject(string $id): object;\n\n    /**\n     * Calls the object method that will load the routes.\n     */\n    public function load(mixed $resource, ?string $type = null): RouteCollection\n    {\n        if (!preg_match('/^[^\\:]+(?:::(?:[^\\:]+))?$/', $resource)) {\n            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'));\n        }\n\n        $parts = explode('::', $resource);\n        $method = $parts[1] ?? '__invoke';\n\n        $loaderObject = $this->getObject($parts[0]);\n\n        if (!\\is_callable([$loaderObject, $method])) {\n            throw new \\BadMethodCallException(\\sprintf('Method \"%s\" not found on \"%s\" when importing routing resource \"%s\".', $method, get_debug_type($loaderObject), $resource));\n        }\n\n        $routeCollection = $loaderObject->$method($this, $this->env);\n\n        if (!$routeCollection instanceof RouteCollection) {\n            $type = get_debug_type($routeCollection);\n\n            throw new \\LogicException(\\sprintf('The \"%s::%s()\" method must return a RouteCollection: \"%s\" returned.', get_debug_type($loaderObject), $method, $type));\n        }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/symfony/routing/blob/83fa223250b50f4f018c011e101c330e65ac63cc/Loader/ObjectLoader.php#L21-L57","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before (config/packages/routing.yaml)\napp_routes:\n    resource: 'App\\Routing\\RoutesLoader::load'\n    type: service\n\n# after\napp_routes:\n    resource: 'app.routing.routes_loader::load'\n    type: service","handlingStrategy":"validation","validationCode":"if (!preg_match('/^[^:]+(?:::(?:[^:]+))?$/', $resource)) {\n    throw new \\InvalidArgumentException('Resource must be \"object_id::method\" or \"object_id\".');\n}","typeGuard":"function isValidObjectResource(string $resource): bool { return preg_match('/^[^:]+(?:::(?:[^:]+))?$/', $resource) === 1; }","tryCatchPattern":"try { $collection = $loader->load($resource, 'service'); } catch (\\InvalidArgumentException $e) { /* fix resource format to object_id::method */ }","preventionTips":["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"],"tags":["symfony","routing","object-loader","argument-format"],"backgroundTag":"invalid-argument-format","analyzedSha":"83fa223250b50f4f018c011e101c330e65ac63cc","analyzedAt":"2026-09-14T03:19:46.280Z","contentChangedAt":"2026-09-14T03:19:46.280Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}