{"record":{"id":"3b2d809595d5dabd","repo":"microsoft/semantic-kernel","slug":"no-iollamaapiclient-implementations-found-in-the-s-3b2d80","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.cs","lineNumber":125,"sourceCode":"    /// <returns>The updated service collection.</returns>\n    public static IServiceCollection AddOllamaTextGeneration(\n        this IServiceCollection services,\n        OllamaApiClient? ollamaClient = null,\n        string? serviceId = null)\n    {\n        Verify.NotNull(services);\n\n        return services.AddKeyedSingleton<ITextGenerationService>(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            return new OllamaTextGenerationService(\n                ollamaClient: ollamaClient,\n                loggerFactory: loggerFactory);\n        });\n    }\n\n    #endregion\n\n    #region Chat Completion\n\n    /// <summary>\n    /// Add Ollama Chat Completion and Text Generation services to the specified service collection.\n    /// </summary>\n    /// <param name=\"services\">The target service collection.</param>\n    /// <param name=\"modelId\">The model for text generation.</param>\n    /// <param name=\"endpoint\">The endpoint to Ollama hosted service.</param>","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Ollama/Extensions/OllamaServiceCollectionExtensions.cs#L107-L143","documentation":"Thrown as an InvalidOperationException inside the AddOllamaTextGeneration DI factory (legacy ITextGenerationService path) when no OllamaApiClient can be resolved. All four DI resolution attempts (keyed OllamaApiClient, keyed IOllamaApiClient, non-keyed OllamaApiClient, IOllamaApiClient) returned null.","triggerScenarios":"Calling services.AddOllamaTextGeneration(...) without registering an OllamaApiClient or IOllamaApiClient, and without passing a client instance argument.","commonSituations":"Using the older ITextGenerationService API path without registering the client; migration from a custom registration that was removed; Ollama not running so client factory returned null.","solutions":["Register the OllamaApiClient before calling AddOllamaTextGeneration.","Pass a client instance directly to the method if you manage lifecycle externally.","Switch to the newer AddOllamaChatClient API if using the current Ollama library."],"exampleFix":"// before\nbuilder.Services.AddOllamaTextGeneration(modelId: \"llama3\");\n\n// after\nbuilder.Services.AddOllamaApiClient(new Uri(\"http://localhost:11434\"));\nbuilder.Services.AddOllamaTextGeneration(modelId: \"llama3\");","handlingStrategy":"validation","validationCode":"using var scope = app.Services.CreateScope();\nif (scope.ServiceProvider.GetService<OllamaApiClient>() is null)\n    throw new InvalidOperationException(\"OllamaApiClient not registered.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register OllamaApiClient before calling AddOllamaTextGeneration.","Consider migrating to the newer AddOllamaChatClient API.","Add a startup check that resolves the service to fail fast."],"tags":["ollama","dependency-injection","text-generation","service-registration"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}