{"record":{"id":"d277d33eb8629e85","repo":"microsoft/semantic-kernel","slug":"an-error-occurred-while-initializing-the-nameof-i","errorCode":null,"errorMessage":"An error occurred while initializing the {nameof(IEmbeddingGenerator)}: {ex.Message}","messagePattern":"An error occurred while initializing the (.+?): (.+?)","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.Amazon/Bedrock/Extensions/BedrockServiceCollectionExtensions.DependencyInjection.cs","lineNumber":131,"sourceCode":"                {\n                    // Cast to AmazonServiceClient and subscribe to the event\n                    ((AmazonServiceClient)runtime).BeforeRequestEvent += BedrockClientUtilities.BedrockServiceClientRequestHandler;\n                }\n\n                var builder = runtime.AsIEmbeddingGenerator(modelId).AsBuilder();\n\n                if (loggerFactory is not null)\n                {\n                    builder.UseLogging(loggerFactory);\n                }\n\n                builder.UseOpenTelemetry(loggerFactory, openTelemetrySourceName, openTelemetryConfig);\n\n                return builder.Build(serviceProvider);\n            }\n            catch (Exception ex)\n            {\n                throw new KernelException($\"An error occurred while initializing the {nameof(IEmbeddingGenerator)}: {ex.Message}\", ex);\n            }\n        });\n\n        return services;\n    }\n}\n","sourceCodeStart":113,"sourceCodeEnd":138,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Amazon/Bedrock/Extensions/BedrockServiceCollectionExtensions.DependencyInjection.cs#L113-L138","documentation":"Thrown by the AddBedrockTextEmbeddingGenerator DI extension when the MEAI embedding-generator Build pipeline (UseLogging, UseOpenTelemetry, Build) throws. Wrapped as a KernelException whose Message embeds the inner ex.Message. Mirrors error 307 but for the IEmbeddingGenerator registration.","triggerScenarios":"Calling services.AddBedrockTextEmbeddingGenerator(...) and the Build throws: missing AWS credentials, OpenTelemetry misconfiguration, package version mismatch, or a null loggerFactory. The embedding-specific service factory also runs, so an unsupported embedding modelId (NotSupportedException from CreateTextEmbeddingService) gets wrapped here too.","commonSituations":"Same as 307 plus: passing a non-embedding modelId (e.g. a chat model) to the embedding generator registration, which makes BedrockServiceFactory throw 'Unsupported model provider' that then surfaces wrapped here.","solutions":["Inspect ex.InnerException of the KernelException for the true cause.","Use a valid embedding modelId ('amazon.titan-embed-text-v2:0' or 'cohere.embed-*').","Resolve AWS credentials and align MEAI package versions.","Provide a non-null openTelemetrySourceName only when OTel is configured."],"exampleFix":"// before\nservices.AddBedrockTextEmbeddingGenerator(\"anthropic.claude-3-5-sonnet-20240620-v1:0\");\n// wraps 'Unsupported model provider: anthropic'\n\n// after\nservices.AddBedrockTextEmbeddingGenerator(\"amazon.titan-embed-text-v2:0\");","handlingStrategy":"validation","validationCode":"// validate modelId is a supported embedding id before registration\nstatic bool IsEmbeddingId(string id)\n{\n    var parts = id.Split('.');\n    return parts.Length > 1 && (parts[0].Equals(\"amazon\", StringComparison.OrdinalIgnoreCase) && parts[1].StartsWith(\"titan-embed-text\", StringComparison.OrdinalIgnoreCase))\n         || (parts[0].Equals(\"cohere\", StringComparison.OrdinalIgnoreCase) && parts[1].StartsWith(\"embed-\", StringComparison.OrdinalIgnoreCase));\n}","typeGuard":null,"tryCatchPattern":"try { services.AddBedrockTextEmbeddingGenerator(modelId); }\ncatch (KernelException ex) { throw new InvalidOperationException($\"Bedrock embedding generator init failed: {ex.InnerException?.Message ?? ex.Message}\", ex); }","preventionTips":["Use an embedding modelId, not a chat/text id.","Resolve AWS credentials and align MEAI package versions.","Inspect KernelException.InnerException to find the wrapped root cause."],"tags":["bedrock","dependency-injection","embeddings","startup","csharp"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}