{"record":{"id":"ed7620ae58758c45","repo":"microsoft/aspire","slug":"connection-string-is-unavailable-ed7620","errorCode":null,"errorMessage":"Connection string is unavailable","messagePattern":"Connection string is unavailable","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"warning","filePath":"src/Aspire.Hosting.Oracle/OracleDatabaseBuilderExtensions.cs","lineNumber":57,"sourceCode":"        var passwordParameter = password?.Resource ?? ParameterResourceBuilderExtensions.CreateDefaultPasswordParameter(builder, $\"{name}-password\");\n\n        var oracleDatabaseServer = new OracleDatabaseServerResource(name, passwordParameter);\n\n        string? connectionString = null;\n\n        builder.Eventing.Subscribe<ConnectionStringAvailableEvent>(oracleDatabaseServer, async (@event, ct) =>\n        {\n            connectionString = await oracleDatabaseServer.ConnectionStringExpression.GetValueAsync(ct).ConfigureAwait(false);\n\n            if (connectionString == null)\n            {\n                throw new DistributedApplicationException($\"ConnectionStringAvailableEvent was published for the '{oracleDatabaseServer.Name}' resource but the connection string was null.\");\n            }\n        });\n\n        var healthCheckKey = $\"{name}_check\";\n        builder.Services.AddHealthChecks()\n            .AddOracle(sp => connectionString ?? throw new InvalidOperationException(\"Connection string is unavailable\"), name: healthCheckKey);\n\n        return builder.AddResource(oracleDatabaseServer)\n                      .WithEndpoint(port: port, targetPort: 1521, name: OracleDatabaseServerResource.PrimaryEndpointName)\n                      .WithImage(OracleContainerImageTags.Image, OracleContainerImageTags.Tag)\n                      .WithImageRegistry(OracleContainerImageTags.Registry)\n                      .WithIconName(\"DatabaseMultiple\")\n                      .WithEnvironment(context =>\n                      {\n                          context.EnvironmentVariables[PasswordEnvVarName] = oracleDatabaseServer.PasswordParameter;\n                      })\n                      .WithHealthCheck(healthCheckKey);\n    }\n\n    /// <summary>\n    /// Adds a Oracle Database database to the application model.\n    /// </summary>\n    /// <param name=\"builder\">The Oracle Database server resource builder.</param>\n    /// <param name=\"name\">The name of the resource. This name will be used as the connection string name when referenced in a dependency.</param>","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Oracle/OracleDatabaseBuilderExtensions.cs#L39-L75","documentation":"The Oracle health check registered by AddOracle resolves the captured connection string via a factory: connectionString ?? throw new InvalidOperationException(\"Connection string is unavailable\"). If the health check runs before the ConnectionStringAvailableEvent handler has populated the field, the check fails with this error. It is a timing/state issue between the event subscription and the health check execution.","triggerScenarios":"Health check executes before the ConnectionStringAvailableEvent callback assigned the connectionString local (e.g. resource unhealthy before connection string resolution, or event never fired).","commonSituations":"AppHost startup races where the health check runs early; the connection-string event never fired due to a failed resource start; inspection of health status during startup.","solutions":["Wait for the resource to become running/healthy rather than querying health status during startup.","If the event never fires, fix the underlying resource startup failure that prevents connection string resolution.","Use the resource's ConnectionStringExpression directly in the health check instead of the cached local."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await healthCheckService.CheckHealthAsync(); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Connection string is unavailable\")) { logger.LogWarning(\"Oracle health check ran before connection string resolved; retry after startup.\"); }","preventionTips":["Only inspect health status after the AppHost reports resources running","Investigate why ConnectionStringAvailableEvent did not fire if the error persists","Prefer resolving the connection string lazily from the resource expression in custom checks"],"tags":["aspire","oracle","health-check","connection-string"],"backgroundTag":"missing-config-value","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}