{"record":{"id":"93267ff2af7dccfb","repo":"microsoft/semantic-kernel","slug":"no-iollamaapiclient-implementations-found-in-the-s","errorCode":null,"errorMessage":"No IOllamaApiClient implementations found in the service collection.","messagePattern":"No IOllamaApiClient implementations found in the service collection\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.Ollama/Extensions/OllamaServiceCollectionExtensions.DependencyInjection.cs","lineNumber":114,"sourceCode":"    /// <returns>The updated service collection.</returns>\n    public static IServiceCollection AddOllamaChatClient(\n        this IServiceCollection services,\n        OllamaApiClient? ollamaClient = null,\n        string? serviceId = null)\n    {\n        Verify.NotNull(services);\n\n        return services.AddKeyedSingleton<IChatClient>(serviceId, (serviceProvider, _) =>\n        {\n            var loggerFactory = serviceProvider.GetService<ILoggerFactory>();\n            ollamaClient ??= serviceProvider.GetKeyedService<OllamaApiClient>(serviceId);\n            ollamaClient ??= serviceProvider.GetKeyedService<IOllamaApiClient>(serviceId) as OllamaApiClient;\n            ollamaClient ??= serviceProvider.GetService<OllamaApiClient>();\n            ollamaClient ??= serviceProvider.GetRequiredService<IOllamaApiClient>() as OllamaApiClient;\n\n            if (ollamaClient is null)\n            {\n                throw new InvalidOperationException($\"No {nameof(IOllamaApiClient)} implementations found in the service collection.\");\n            }\n\n            var builder = ((IChatClient)ollamaClient).AsBuilder();\n            if (loggerFactory is not null)\n            {\n                builder.UseLogging(loggerFactory);\n            }\n\n            return builder\n                .UseKernelFunctionInvocation(loggerFactory)\n                .Build(serviceProvider);\n        });\n    }\n\n    #endregion\n\n    #region Text Embeddings\n","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Ollama/Extensions/OllamaServiceCollectionExtensions.DependencyInjection.cs#L96-L132","documentation":"Thrown as an InvalidOperationException inside the AddOllamaChatClient DI factory when none of the resolution attempts (keyed OllamaApiClient, keyed IOllamaApiClient, non-keyed OllamaApiClient, or IOllamaApiClient) yield a non-null OllamaApiClient instance. The extension tries multiple DI resolution paths and fails only when all return null.","triggerScenarios":"Calling services.AddOllamaChatClient(...) without first registering an OllamaApiClient or IOllamaApiClient in the service collection, and without passing a pre-built ollamaClient argument.","commonSituations":"Forgot to call AddOllamaApiClient or register the client; using a keyed service with a different key than the one passed; the Ollama endpoint configuration is missing so the client was never constructed.","solutions":["Register an OllamaApiClient before calling AddOllamaChatClient: services.AddOllamaApiClient(new Uri(\"http://localhost:11434\")).","Pass an existing OllamaApiClient instance directly to AddOllamaChatClient if using a custom configuration.","Verify the service ID/key matches between registration and resolution if using keyed services."],"exampleFix":"// before\nbuilder.Services.AddOllamaChatClient(\"myChat\");\n\n// after\nbuilder.Services.AddOllamaApiClient(new Uri(\"http://localhost:11434\"));\nbuilder.Services.AddOllamaChatClient(\"myChat\");","handlingStrategy":"validation","validationCode":"// Validate at startup after building the service provider\nusing var scope = app.Services.CreateScope();\nvar client = scope.ServiceProvider.GetService<OllamaApiClient>();\nif (client is null)\n    throw new InvalidOperationException(\"OllamaApiClient not registered.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call AddOllamaApiClient before any AddOllama* method.","Use startup validation to verify the client is resolvable.","Document DI registration order in your project setup guide."],"tags":["ollama","dependency-injection","service-registration","invalid-operation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}