{"record":{"id":"a17b96f376097b01","repo":"github/copilot-sdk","slug":"uriruntimeconnection-url-must-be-a-non-empty-strin-a17b96","errorCode":null,"errorMessage":"UriRuntimeConnection.Url must be a non-empty string.","messagePattern":"UriRuntimeConnection\\.Url must be a non-empty string\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Client.cs","lineNumber":173,"sourceCode":"                break;\n\n            case InProcessRuntimeConnection:\n                break;\n\n            case TcpRuntimeConnection tcp:\n                if (tcp.ConnectionToken is { Length: 0 })\n                {\n                    throw new ArgumentException(\"ConnectionToken must be a non-empty string or null.\", nameof(options));\n                }\n                // Auto-generate a connection token when the SDK spawns the runtime over TCP\n                // so the loopback listener is safe by default.\n                tcp.ConnectionToken ??= Guid.NewGuid().ToString();\n                break;\n\n            case UriRuntimeConnection uri:\n                if (string.IsNullOrEmpty(uri.Url))\n                {\n                    throw new ArgumentException(\"UriRuntimeConnection.Url must be a non-empty string.\", nameof(options));\n                }\n                if (!string.IsNullOrEmpty(_options.GitHubToken) || _options.UseLoggedInUser != null)\n                {\n                    throw new ArgumentException(\"GitHubToken and UseLoggedInUser cannot be combined with RuntimeConnection.ForUri (the existing runtime manages its own auth).\", nameof(options));\n                }\n                var parsed = ParseRuntimeUrl(uri.Url);\n                _optionsHost = parsed.Host.Trim('[', ']');\n                _optionsPort = parsed.Port;\n                break;\n\n            default:\n                throw new ArgumentException($\"Unsupported RuntimeConnection type: {_connection.GetType().Name}\", nameof(options));\n        }\n\n        ValidateEnvironmentOptions(_options, _connection);\n\n        _logger = _options.Logger ?? NullLogger.Instance;\n        _onListModels = _options.OnListModels;","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/dotnet/src/Client.cs#L155-L191","documentation":"Argument-validation guard in CopilotClient's connection-options handling (same ArgumentException pattern as the sibling TcpRuntimeConnection check): a UriRuntimeConnection was supplied whose Url is null, empty, or not a string. The faulting input is the RuntimeConnection option; supply a valid non-empty absolute URL before constructing the client.","triggerScenarios":"new CopilotClient(options) with options.Connection = new UriRuntimeConnection { Url = null } or Url = \"\"; RuntimeConnection.ForUri built from a null/empty variable.","commonSituations":"Runtime URL read from an unset or empty environment variable/config key; constructing the options object without assigning Url; template strings left unsubstituted.","solutions":["Set UriRuntimeConnection.Url to a valid runtime URL (e.g. http://127.0.0.1:port)","Validate the config/env value before building options","Fall back to a default connection (omit Connection) when no URL is configured"],"exampleFix":"// before\noptions.Connection = new UriRuntimeConnection { Url = cfg[\"RuntimeUrl\"] }; // empty\n// after\nvar url = cfg[\"RuntimeUrl\"];\nif (string.IsNullOrEmpty(url)) throw new InvalidOperationException(\"RuntimeUrl must be configured\");\noptions.Connection = new UriRuntimeConnection { Url = url };","handlingStrategy":"validation","validationCode":"if (options.Connection is UriRuntimeConnection u && string.IsNullOrEmpty(u.Url)) throw new InvalidOperationException(\"Configure RuntimeConnection.ForUri with a non-empty URL\");","typeGuard":null,"tryCatchPattern":"try { client = new CopilotClient(options); } catch (ArgumentException ex) when (ex.Message.Contains(\"UriRuntimeConnection.Url\")) { log.LogError(ex, \"Runtime URL not configured\"); }","preventionTips":["Validate the URL env/config key before building options","Fail fast with a clear config error in the app's startup path","Prefer omitting Connection entirely when no external runtime is present"],"tags":["dotnet","uri","validation"],"backgroundTag":"empty-required-field","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}