{"record":{"id":"31397bd5f907a237","repo":"microsoft/autogen","slug":"requesturi-is-null","errorCode":null,"errorMessage":"RequestUri is null","messagePattern":"RequestUri is null","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.LMStudio/LMStudioAgent.cs","lineNumber":84,"sourceCode":"        };\n\n        return new OpenAIClient(\"api-key\", option);\n    }\n\n    private sealed class CustomHttpClientHandler : HttpClientHandler\n    {\n        private Uri _modelServiceUrl;\n\n        public CustomHttpClientHandler(Uri modelServiceUrl)\n        {\n            _modelServiceUrl = modelServiceUrl;\n        }\n\n        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\n        {\n            // request.RequestUri = new Uri($\"{_modelServiceUrl}{request.RequestUri.PathAndQuery}\");\n            var uriBuilder = new UriBuilder(_modelServiceUrl);\n            uriBuilder.Path = request.RequestUri?.PathAndQuery ?? throw new InvalidOperationException(\"RequestUri is null\");\n            request.RequestUri = uriBuilder.Uri;\n            return base.SendAsync(request, cancellationToken);\n        }\n    }\n}\n","sourceCodeStart":66,"sourceCodeEnd":90,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.LMStudio/LMStudioAgent.cs#L66-L90","documentation":"LMStudioAgent routes HTTP traffic through CustomHttpClientHandler, which rewrites each request's URI to the configured model service URL. The rewrite reads request.RequestUri.PathAndQuery; if the outgoing HttpRequestMessage has a null RequestUri, UriBuilder cannot proceed and this InvalidOperationException is thrown.","triggerScenarios":"Creating an LMStudioAgent and issuing a completion request where the underlying HttpClient sends a request with a relative/null URI that this handler did not expect — typically a misconstructed base address in modelServiceUrl or an SDK/client version whose request pipeline differs.","commonSituations":"Passing a malformed Uri to the LMStudioAgent constructor (e.g. new Uri(\"\" ) variants or a URL without scheme); mixing Google Cloud library versions where the generated client builds request URIs differently; local LM Studio server moved/changed base path.","solutions":["Verify the modelServiceUrl passed to LMStudioAgent is an absolute URI including scheme and host (e.g. http://127.0.0.1:1234).","Confirm the local LM Studio server is running and reachable at that URL.","Align the Google.Cloud.AIPlatform / REST client package versions with the AutoGen.LMStudio version you use.","If it persists, report upstream — a null RequestUri at this point indicates a client-pipeline mismatch, not a user input error."],"exampleFix":"// before\nvar agent = new LMStudioAgent(\"agent\", modelServiceUrl: new Uri(\"localhost:1234\", UriKind.Relative));\n\n// after\nvar agent = new LMStudioAgent(\"agent\", modelServiceUrl: new Uri(\"http://127.0.0.1:1234\"));","handlingStrategy":"validation","validationCode":"if (!modelServiceUrl.IsAbsoluteUri || string.IsNullOrEmpty(modelServiceUrl.Scheme))\n{\n    throw new ArgumentException(\"modelServiceUrl must be absolute, e.g. http://127.0.0.1:1234\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always construct the agent URL with scheme+host","Health-check the LM Studio server before starting the agent","Pin compatible package versions"],"tags":["lmstudio","http-client","uri","configuration"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}