Fix: Startet nicht / MySQL-Timeout ohne UI (Config- & Startup-Härtung)
Ursachen (App startete aus bin/ bzw. per Doppelklick ohne UI): 1. appsettings.Local.json (MySQL-Connection) wurde NICHT ins Output kopiert und nur relativ zum Arbeitsverzeichnis geladen -> leere Connection -> Pomelo fiel auf localhost:3306 zurueck -> "Connect Timeout expired". 2. ServerVersion.AutoDetect(conn) oeffnet beim Options-Bau eine blockierende DB-Verbindung -> haengt/crasht den Start, wenn die DB nicht erreichbar ist. 3. CopyTradingEngine.StartAsync lud den MarketCache ungeschuetzt -> DB-Fehler riss AppHost.Start() ab, bevor die UI erschien. Fixes: - csproj: appsettings.Local.json mit ins Output kopieren (CopyToOutputDirectory). - Program: UseContentRoot(AppContext.BaseDirectory) -> Config wird immer neben der EXE gesucht (Main + Smoke-Test). - ServerVersion fest gepinnt: DatabaseServerVersion.Value = MariaDB 11.8.6 (wie am Server erkannt); AddCorePersistence + CopyTradingModule nutzen sie statt AutoDetect. Kein blockierender Connect mehr beim Start. - CopyTradingEngine-Preload in try/catch: DB-Fehler bricht den Start nicht mehr ab. - Neuer Diagnose-CLI --db-version (gibt @@version aus). Verifiziert: --smoke-ui aus fremdem Arbeitsverzeichnis laeuft gruen (3 Accounts / 32 Trader hydriert, alle Views + Launcher OK). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
6f478e8764
commit
f1451b547c
+39
@@ -48,6 +48,13 @@ internal static class Program
|
||||
return;
|
||||
}
|
||||
|
||||
// Diagnose: gibt die MySQL-Serverversion aus (für das ServerVersion-Pinning). Kein UI.
|
||||
if (args.Length > 0 && string.Equals(args[0], "--db-version", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
RunDbVersion();
|
||||
return;
|
||||
}
|
||||
|
||||
ApplicationConfiguration.Initialize();
|
||||
|
||||
var modules = new System.Collections.Generic.List<IPolyTraderModule>
|
||||
@@ -56,6 +63,9 @@ internal static class Program
|
||||
};
|
||||
|
||||
AppHost = Host.CreateDefaultBuilder()
|
||||
// Config immer neben der EXE suchen (nicht im Arbeitsverzeichnis), damit die App
|
||||
// auch beim Start aus bin/ oder per Doppelklick ihre appsettings findet.
|
||||
.UseContentRoot(AppContext.BaseDirectory)
|
||||
// Host.CreateDefaultBuilder lädt appsettings.Local.json NICHT (nur appsettings.json
|
||||
// + appsettings.{Environment}.json). Die gitignorierte Local-Datei hält aber die
|
||||
// MySQL-Connection – daher hier explizit ergänzen, sonst bleibt sie leer.
|
||||
@@ -252,6 +262,34 @@ internal static class Program
|
||||
Services.ConfigMigrator.VerifyMySql(mySql);
|
||||
}
|
||||
|
||||
private static void RunDbVersion()
|
||||
{
|
||||
var config = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
|
||||
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: true)
|
||||
.AddJsonFile("appsettings.Local.json", optional: true)
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
|
||||
var conn = config["Database:MySqlConnectionString"] ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(conn))
|
||||
{
|
||||
Console.WriteLine("FEHLER: Database:MySqlConnectionString fehlt (appsettings.Local.json).");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using var c = new MySqlConnector.MySqlConnection(conn);
|
||||
c.Open();
|
||||
Console.WriteLine($"ServerVersion: {c.ServerVersion}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"FEHLER: {ex.GetType().Name}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Headless-Smoke-Test: baut einen minimalen Host (Persistenz + State + Modul-Registrierung
|
||||
/// + Shell/Launcher), hydriert den State aus MySQL und konstruiert jede registrierte View
|
||||
@@ -265,6 +303,7 @@ internal static class Program
|
||||
var modules = new System.Collections.Generic.List<IPolyTraderModule> { new CopyTradingModule() };
|
||||
|
||||
using var host = Host.CreateDefaultBuilder()
|
||||
.UseContentRoot(AppContext.BaseDirectory)
|
||||
.ConfigureAppConfiguration((context, config) =>
|
||||
config.AddJsonFile("appsettings.Local.json", optional: true, reloadOnChange: false))
|
||||
.ConfigureServices((context, services) =>
|
||||
|
||||
Reference in New Issue
Block a user