ArgumentNulLexception in MySQL HealthCheck vor dem Erstellen von ASP.NET -KernanwendungC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 ArgumentNulLexception in MySQL HealthCheck vor dem Erstellen von ASP.NET -Kernanwendung

Post by Anonymous »

Ich habe eine DotNet 8 ASP -Kernanwendung und ich versuche, mit ASPNetCore einen HealthCheck für meine Azure -Datenbank mit ASPNetCore.HealthChecks.mysql Nuget und Retrevers -Verbindungszeichenfolge aus der Azure -App -Konfiguration hinzuzufügen, aber ich erhalte diesen Fehler
Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString') 2025-02-13T17:25:58.240518977Z at Guard.ThrowIfNull[T](T argument, Boolean throwOnEmptyString, String paramName) in /home/runner/work/AspNetCore.Diagnostics.HealthChecks/AspNetCore.Diagnostics.HealthChecks/src/CallerArgumentExpressionAttribute.cs:line 49 2025-02-13T17:25:58.240534540Z at Microsoft.Extensions.DependencyInjection.MySqlHealthCheckBuilderExtensions.AddMySql(IHealthChecksBuilder builder, String connectionString, String healthQuery, Action`1 configure, String name, Nullable`1 failureStatus, IEnumerable`1 tags, Nullable`1 timeout) in /home/runner/work/AspNetCore.Diagnostics.HealthChecks/AspNetCore.Diagnostics.HealthChecks/src/HealthChecks.MySql/DependencyInjection/MySqlHealthCheckBuilderExtensions.cs:line 76 2025-02-13T17:25:58.240539703Z at Program.$(String[] args) in /home/vsts/work/1/s/src/ProjectName/Program.cs:line 90
< /code>
Dies ist mein Programm.cs Code: < /p>
IConfigurationSection configurationConnectionStringsSection = builder.Configuration.GetSection(ConnectionStringsSettings.Section);
builder.Services.Configure(configurationConnectionStringsSection);
ConnectionStringsSettings? connectionStringsOptions = configurationConnectionStringsSection.Get()
?? throw new InvalidOperationException($"Invalid settings for {nameof(ConnectionStringsSettings)}");
if (!builder.Environment.IsDevelopment())
{
// Bind Settings from Azure App Configuration

builder.Services.Configure
(builder.Configuration.GetSection("ConnectionStrings"));
builder.Services.AddAzureAppConfiguration();

builder.Configuration.AddAzureAppConfiguration(options =>
{
options.Connect(new Uri(azureAppConfigurationOptions.Uri), new
DefaultAzureCredential(defaultAzureCredentialOptions));

options.ConfigureKeyVault(kv =>
{
kv.SetCredential(new DefaultAzureCredential(defaultAzureCredentialOptions));
});
});

builder.Services
.AddHealthChecks()
.AddApplicationStatus("Self")
.AddMySql(connectionStringsOptions.MyConnectionString);
}

var app = builder.Build();
< /code>
Wenn ich diesen Code ausführe, erhalte ich ArgumentNulLexception, da ConnectionStringsopions Irgendwelche Tipps, um diese Art von Fehler beim Starten der Anwendung zu vermeiden?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post