{"record":{"id":"1513ff2295fc2ca7","repo":"microsoft/semantic-kernel","slug":"the-nameof-httpclient-nameof-httpclient-basead","errorCode":null,"errorMessage":"The {nameof(httpClient)}.{nameof(HttpClient.BaseAddress)} and {nameof(endpoint)} are both null or empty. Please ensure at least one is provided.","messagePattern":"The (.+?)\\.(.+?) and (.+?) are both null or empty\\. Please ensure at least one is provided\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.AzureOpenAI/Services/AzureOpenAITextToImageService.cs","lineNumber":53,"sourceCode":"    /// <param name=\"modelId\">Azure OpenAI model id, see https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource</param>\n    /// <param name=\"httpClient\">Custom <see cref=\"HttpClient\"/> for HTTP requests.</param>\n    /// <param name=\"loggerFactory\">The <see cref=\"ILoggerFactory\"/> to use for logging. If null, no logging will be performed.</param>\n    /// <param name=\"apiVersion\">Azure OpenAI service API version, see https://learn.microsoft.com/azure/cognitive-services/openai/quickstart</param>\n    public AzureOpenAITextToImageService(\n        string deploymentName,\n        string endpoint,\n        string apiKey,\n        string? modelId,\n        HttpClient? httpClient = null,\n        ILoggerFactory? loggerFactory = null,\n        string? apiVersion = null)\n    {\n        Verify.NotNullOrWhiteSpace(apiKey);\n\n        var connectorEndpoint = !string.IsNullOrWhiteSpace(endpoint) ? endpoint! : httpClient?.BaseAddress?.AbsoluteUri;\n        if (connectorEndpoint is null)\n        {\n            throw new ArgumentException($\"The {nameof(httpClient)}.{nameof(HttpClient.BaseAddress)} and {nameof(endpoint)} are both null or empty. Please ensure at least one is provided.\");\n        }\n\n        var options = AzureClientCore.GetAzureOpenAIClientOptions(httpClient, apiVersion); // DALL-E 3 is supported in the latest API releases - https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#image-generation\n\n        var azureOpenAIClient = new AzureOpenAIClient(new Uri(connectorEndpoint), new ApiKeyCredential(apiKey), options);\n\n        this._client = new(deploymentName, azureOpenAIClient, loggerFactory?.CreateLogger(this.GetType()));\n\n        if (modelId is not null)\n        {\n            this._client.AddAttribute(AIServiceExtensions.ModelIdKey, modelId);\n        }\n    }\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"AzureOpenAITextToImageService\"/> class.\n    /// </summary>\n    /// <param name=\"deploymentName\">Azure OpenAI deployment name, see https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource</param>","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.AzureOpenAI/Services/AzureOpenAITextToImageService.cs#L35-L71","documentation":"Thrown by the AzureOpenAITextToImageService constructor (apiKey overload) when both the endpoint string parameter and httpClient.BaseAddress are null or empty. The constructor resolves the final endpoint as endpoint ?? httpClient?.BaseAddress?.AbsoluteUri; if the result is null, there is no target URI for the Azure OpenAI service and construction cannot proceed.","triggerScenarios":"Calling the constructor with endpoint set to null, empty string, or whitespace AND either httpClient is null or httpClient.BaseAddress is null. The Verify.NotNullOrWhiteSpace(apiKey) check passes first, so apiKey is valid but the endpoint resolution fails.","commonSituations":"Reading endpoint from configuration/environment that is not set (e.g. Environment.GetEnvironmentVariable returns null). Passing endpoint as null and relying on a shared HttpClient that was created without setting BaseAddress. Misconfigured dependency injection where the endpoint binding is missing.","solutions":["Provide a non-empty endpoint string: new AzureOpenAITextToImageService(\"deployment\", \"https://myresource.openai.azure.com/\", apiKey).","If using a shared HttpClient, set its BaseAddress: httpClient.BaseAddress = new Uri(\"https://myresource.openai.azure.com/\").","Read the endpoint from configuration with a fallback or validation: var endpoint = config[\"AzureOpenAI:Endpoint\"] ?? throw new InvalidOperationException(\"Endpoint not configured\").","Ensure the endpoint string is the Azure OpenAI resource base URL (e.g. https://<resource>.openai.azure.com/), not just the resource name."],"exampleFix":"// before — endpoint is null, httpClient has no BaseAddress\nvar svc = new AzureOpenAITextToImageService(\n    \"dalle3\", endpoint: null, apiKey, httpClient: client);\n\n// after — pass the endpoint explicitly\nvar svc = new AzureOpenAITextToImageService(\n    \"dalle3\", \"https://myresource.openai.azure.com/\", apiKey);","handlingStrategy":"validation","validationCode":"string endpoint = configEndpoint;\nif (string.IsNullOrWhiteSpace(endpoint))\n{\n    endpoint = httpClient?.BaseAddress?.AbsoluteUri;\n}\nif (string.IsNullOrWhiteSpace(endpoint))\n{\n    throw new InvalidOperationException(\n        \"Azure OpenAI endpoint must be provided via the 'endpoint' parameter or HttpClient.BaseAddress.\");\n}\n// safe to construct\nvar service = new AzureOpenAITextToImageService(deployment, endpoint, apiKey, httpClient);","typeGuard":"static bool HasValidEndpoint(string? endpoint, HttpClient? http) =>\n    !string.IsNullOrWhiteSpace(endpoint) ||\n    (http?.BaseAddress?.AbsoluteUri is not null && !string.IsNullOrWhiteSpace(http.BaseAddress.AbsoluteUri));","tryCatchPattern":"try\n{\n    var svc = new AzureOpenAITextToImageService(deploy, endpoint, apiKey, httpClient);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"both null or empty\"))\n{\n    throw new ConfigurationException(\"AzureOpenAI:Endpoint is missing. Configure it in appsettings or environment.\", ex);\n}","preventionTips":["Always validate endpoint configuration at application startup using the Options pattern with ValidateOnStart().","Store the endpoint in a well-known configuration key (e.g. 'AzureOpenAI:Endpoint') and fail fast if missing.","If using a shared HttpClient, set BaseAddress explicitly to avoid ambiguity."],"tags":["azure-openai","endpoint","configuration","argument-exception"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}