{"record":{"id":"ac8112f0f43fb565","repo":"dotnet/aspnetcore","slug":"the-hubconnectionbuilder-withurl-method-must-be","errorCode":null,"errorMessage":"The 'HubConnectionBuilder.withUrl' method must be called before building the connection.","messagePattern":"The 'HubConnectionBuilder\\.withUrl' method must be called before building the connection\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts","lineNumber":257,"sourceCode":"\n    /** Creates a {@link @microsoft/signalr.HubConnection} from the configuration options specified in this builder.\n     *\n     * @returns {HubConnection} The configured {@link @microsoft/signalr.HubConnection}.\n     */\n    public build(): HubConnection {\n        // If httpConnectionOptions has a logger, use it. Otherwise, override it with the one\n        // provided to configureLogger\n        const httpConnectionOptions = this.httpConnectionOptions || {};\n\n        // If it's 'null', the user **explicitly** asked for null, don't mess with it.\n        if (httpConnectionOptions.logger === undefined) {\n            // If our logger is undefined or null, that's OK, the HttpConnection constructor will handle it.\n            httpConnectionOptions.logger = this.logger;\n        }\n\n        // Now create the connection\n        if (!this.url) {\n            throw new Error(\"The 'HubConnectionBuilder.withUrl' method must be called before building the connection.\");\n        }\n        const connection = new HttpConnection(this.url, httpConnectionOptions);\n\n        return HubConnection.create(\n            connection,\n            this.logger || NullLogger.instance,\n            this.protocol || new JsonHubProtocol(),\n            this.reconnectPolicy,\n            this._serverTimeoutInMilliseconds,\n            this._keepAliveIntervalInMilliseconds,\n            this._statefulReconnectBufferSize,\n            this._authenticationRefreshOptions);\n    }\n}\n\nfunction isLogger(logger: any): logger is ILogger {\n    return logger.log !== undefined;\n}","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/SignalR/clients/ts/signalr/src/HubConnectionBuilder.ts#L239-L275","documentation":"Thrown by HubConnectionBuilder.build when `this.url` is unset. The builder requires a URL to construct the HttpConnection; withUrl is the only method that populates `this.url`, so build() refuses to construct an HttpConnection with no endpoint.","triggerScenarios":"Calling `.build()` on a HubConnectionBuilder without a preceding `.withUrl(url)` call, or withUrl was invoked on a different builder instance.","commonSituations":"Refactoring that moves withUrl behind a conditional that evaluates false, or copy-pasting a builder setup and dropping the withUrl line.","solutions":["Always call `.withUrl(url)` before `.build()`.","Make withUrl the first call in the builder chain for visibility.","Assert `builder.url` is set in test fixtures before build."],"exampleFix":"// before\nconst conn = new HubConnectionBuilder().configureLogging(LogLevel.Information).build();\n// after\nconst conn = new HubConnectionBuilder()\n  .withUrl(\"/hub\")\n  .configureLogging(LogLevel.Information)\n  .build();","handlingStrategy":"validation","validationCode":"function ensureUrlSet(b: { url?: string }) {\n  if (!b.url) throw new Error(\"withUrl must be called before build\");\n}","typeGuard":"function builderHasUrl(b: { url?: string }): b is { url: string } {\n  return typeof b.url === \"string\" && b.url.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Call withUrl as the first builder step.","Assert builder.url before build in tests.","Avoid conditional withUrl branches that may be skipped."],"tags":["builder","url","configuration"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}