{"record":{"id":"507e80bc7e94e986","repo":"clockworklabs/SpacetimeDB","slug":"http-router-references-unknown-handler-route-han","errorCode":null,"errorMessage":"HTTP router references unknown handler `{route.HandlerFunction}`","messagePattern":"HTTP router references unknown handler `(.+?)`","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"crates/bindings-csharp/Runtime/Internal/Module.cs","lineNumber":371,"sourceCode":"    public static void RegisterHttpHandler<H>()\n        where H : IHttpHandler, new()\n    {\n        var handler = new H();\n        httpHandlers.Add(handler);\n        moduleDef.RegisterHttpHandler(handler.MakeHandlerDef());\n    }\n\n    public static void RegisterHttpRouter(SpacetimeDB.Router router)\n    {\n        foreach (var route in router.GetRoutes())\n        {\n            if (\n                !httpHandlers.Any(handler =>\n                    handler.MakeHandlerDef().SourceName == route.HandlerFunction\n                )\n            )\n            {\n                throw new ArgumentException(\n                    $\"HTTP router references unknown handler `{route.HandlerFunction}`\",\n                    nameof(router)\n                );\n            }\n\n            moduleDef.RegisterHttpRoute(\n                new RawHttpRouteDefV10(\n                    HandlerFunction: route.HandlerFunction,\n                    Method: route.Method,\n                    Path: route.Path\n                )\n            );\n        }\n    }\n\n    public static void RegisterTable<T, View>()\n        where T : IStructuralReadWrite, new()\n        where View : ITableView<View, T>, new()","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/bindings-csharp/Runtime/Internal/Module.cs#L353-L389","documentation":"Module.RegisterHttpRouter cross-checks every route a Router exposes against the generated HTTP handler classes registered in the module, matching route.HandlerFunction to the handler's SourceName (the method's original name). A route naming a method that has no generated handler - renamed, removed, typo'd, or compiled out - throws ArgumentException during module construction, before any request is served.","triggerScenarios":"Renaming or deleting a handler method without updating the router configuration; passing handler names as hand-written strings with typos or casing errors; a router shared/copy-pasted from another module; the handler excluded by conditional compilation.","commonSituations":"Refactoring handler names in code review; splitting a module and moving handlers but keeping the old router; string-based configuration drifting from code.","solutions":["Register routes using nameof(HandlerMethod) instead of string literals so renames become compile errors","After renaming/removing a handler, update every Router that referenced it (search for the old name)","Keep routers and the handlers they reference in the same module/project","Ensure the handler method is actually annotated so the source generator emits a class with that SourceName"],"exampleFix":"// before\nrouter.Route(\"GET\", \"/players\", \"GetPlayerHandler\"); // stale hand-written name -> throws\n\n// after\nrouter.Route(\"GET\", \"/players\", nameof(GetPlayer)); // refactor-safe","handlingStrategy":"validation","validationCode":"// Before RegisterHttpRouter, assert every route points at a real handler method.\nvar known = new HashSet<string>(typeof(Handlers).GetMethods(BindingFlags.Public | BindingFlags.Static).Select(m => m.Name));\nforeach (var route in router.GetRoutes())\n{\n    if (!known.Contains(route.HandlerFunction))\n        throw new ArgumentException($\"Route {route.Method} {route.Path} references unknown handler {route.HandlerFunction}\");\n}\nModule.RegisterHttpRouter(router);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use nameof(HandlerMethod) when registering routes - never string literals","After renaming or removing a handler, grep for its old name in router setup","Keep each Router and its handlers in the same assembly so compile-time name tracking works"],"tags":["csharp","http","router","handler-registration","spacetimedb"],"backgroundTag":"handler-registration-missing","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}