{"record":{"id":"043d5806aee34da5","repo":"microsoft/semantic-kernel","slug":"an-error-occurred-while-initializing-the-nameof-b-043d58","errorCode":null,"errorMessage":"An error occurred while initializing the {nameof(BedrockTextEmbeddingGenerationService)}: {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.cs","lineNumber":144,"sourceCode":"            services.TryAddAWSService<IAmazonBedrockRuntime>();\n        }\n        services.AddKeyedSingleton<ITextEmbeddingGenerationService>(serviceId, (serviceProvider, _) =>\n        {\n            try\n            {\n                IAmazonBedrockRuntime runtime = bedrockRuntime ?? serviceProvider.GetRequiredService<IAmazonBedrockRuntime>();\n                var loggerFactory = serviceProvider.GetService<ILoggerFactory>();\n                // Check if the runtime instance is a proxy object\n                if (runtime.GetType().BaseType == typeof(AmazonServiceClient))\n                {\n                    // Cast to AmazonServiceClient and subscribe to the event\n                    ((AmazonServiceClient)runtime).BeforeRequestEvent += BedrockClientUtilities.BedrockServiceClientRequestHandler;\n                }\n                return new BedrockTextEmbeddingGenerationService(modelId, runtime, loggerFactory);\n            }\n            catch (Exception ex)\n            {\n                throw new KernelException($\"An error occurred while initializing the {nameof(BedrockTextEmbeddingGenerationService)}: {ex.Message}\", ex);\n            }\n        });\n\n        return services;\n    }\n}\n","sourceCodeStart":126,"sourceCodeEnd":151,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.Amazon/Bedrock/Extensions/BedrockServiceCollectionExtensions.cs#L126-L151","documentation":"Thrown by AddBedrockTextEmbeddingGeneration (classic Kernel service DI) when the BedrockTextEmbeddingGenerationService factory throws. The factory resolves IAmazonBedrockRuntime and constructs the embedding service; the service constructor in turn calls BedrockServiceFactory.CreateTextEmbeddingService (which only supports 'amazon'/'cohere'). Any failure is wrapped in a KernelException.","triggerScenarios":"services.AddBedrockTextEmbeddingGeneration(modelId) without a registered IAmazonBedrockRuntime, or with a modelId whose provider is not 'amazon' or 'cohere' (CreateTextEmbeddingService throws NotSupportedException, wrapped here). Cross-region prefix ('us.') is also NOT scrubbed for embeddings, so 'us.amazon.titan-embed-text-v2:0' fails as 'Unsupported model provider: us'.","commonSituations":"Missing runtime registration. Passing a chat/text modelId to the embedding extension. Using a cross-region inference profile prefix for embeddings.","solutions":["Register the runtime: services.AddAWSService<IAmazonBedrockRuntime>();.","Use a supported embedding modelId without a region prefix: 'amazon.titan-embed-text-v2:0' or 'cohere.embed-english-v3:0'.","Inspect ex.InnerException for the precise factory error.","Pass an explicit IAmazonBedrockRuntime if constructed manually."],"exampleFix":"// before\nservices.AddAWSService<IAmazonBedrockRuntime>();\nservices.AddBedrockTextEmbeddingGeneration(\"us.amazon.titan-embed-text-v2:0\");\n// wraps 'Unsupported model provider: us'\n\n// after\nservices.AddAWSService<IAmazonBedrockRuntime>();\nservices.AddBedrockTextEmbeddingGeneration(\"amazon.titan-embed-text-v2:0\");","handlingStrategy":"validation","validationCode":"// strip cross-region prefix and validate provider for embeddings\nstatic string Scrub(string id)\n{\n    foreach (var p in new[] { \"us.\", \"eu.\", \"apac.\" }) if (id.StartsWith(p, StringComparison.OrdinalIgnoreCase)) return id[p.Length..];\n    return id;\n}\nbool ok = Scrub(modelId).Split('.')[0] is \"amazon\" or \"cohere\";","typeGuard":null,"tryCatchPattern":"try { services.AddBedrockTextEmbeddingGeneration(modelId); }\ncatch (KernelException ex) when (ex.InnerException?.Message.StartsWith(\"Unsupported model provider\") == true)\n{ throw new InvalidOperationException(\"Use an amazon. or cohere. embedding modelId without a cross-region prefix.\", ex); }","preventionTips":["Register IAmazonBedrockRuntime before the embedding service.","Avoid cross-region prefixes ('us.', 'eu.', 'apac.') on embedding modelIds.","Inspect KernelException.InnerException for the factory's NotSupportedException."],"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"}