From 0c918e86ae7b6072fb09068f7d4b38f3a4fe43fd Mon Sep 17 00:00:00 2001 From: Yinyin Liu Date: Thu, 12 Feb 2026 07:55:43 +0100 Subject: [PATCH] Fix build errors: FrozenDictionary (.NET 8) and Flurl 3.x API compatibility - Replace FrozenDictionary with IReadOnlyDictionary for .NET 6 compat - Use WithHeader instead of SetHeader for Flurl.Http 3.2.4 - Fix FlurlHttpException error logging for Flurl 3.x Co-Authored-By: Claude Opus 4.6 --- csharp/App/Backend/Services/AlarmKnowledgeBase.cs | 10 ++++------ csharp/App/Backend/Services/DiagnosticService.cs | 5 ++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/csharp/App/Backend/Services/AlarmKnowledgeBase.cs b/csharp/App/Backend/Services/AlarmKnowledgeBase.cs index 6573f36c4..15848c769 100644 --- a/csharp/App/Backend/Services/AlarmKnowledgeBase.cs +++ b/csharp/App/Backend/Services/AlarmKnowledgeBase.cs @@ -1,5 +1,3 @@ -using System.Collections.Frozen; - namespace InnovEnergy.App.Backend.Services; /// @@ -43,7 +41,7 @@ public static class AlarmKnowledgeBase // Register addresses: 0x1048 - 0x10D5 // Recovery types: AUTO (wait), MANUAL (fix and restart), SERVICE (contact service) - private static readonly FrozenDictionary SinexcelAlarms = new Dictionary + private static readonly IReadOnlyDictionary SinexcelAlarms = new Dictionary { // Grid-related alarms ["Abnormal grid voltage"] = new() @@ -958,12 +956,12 @@ public static class AlarmKnowledgeBase Causes = new[] { "Load exceeds generator capacity" }, NextSteps = new[] { "Reduce load", "Fix the cause, then restart" } }, - }.ToFrozenDictionary(); + }; // ── Growatt Alarms ─────────────────────────────────────────────────────── // Format: "Warning XXX" or "Error XXX" or descriptive text - private static readonly FrozenDictionary GrowattAlarms = new Dictionary + private static readonly IReadOnlyDictionary GrowattAlarms = new Dictionary { // Warnings (200-series: PV/String) ["Warning 200"] = new() @@ -1510,5 +1508,5 @@ public static class AlarmKnowledgeBase Causes = new[] { "Too many PV modules in series", "Cold temperature increasing Voc" }, NextSteps = new[] { "Disconnect DC switch immediately", "Check voltage", "Reconfigure strings if needed" } }, - }.ToFrozenDictionary(); + }; } diff --git a/csharp/App/Backend/Services/DiagnosticService.cs b/csharp/App/Backend/Services/DiagnosticService.cs index b2948f3de..ed0b2e30f 100644 --- a/csharp/App/Backend/Services/DiagnosticService.cs +++ b/csharp/App/Backend/Services/DiagnosticService.cs @@ -126,8 +126,7 @@ Reply with ONLY valid JSON, no markdown: }; var responseText = await MistralUrl - .SetHeader("Authorization", $"Bearer {_apiKey}") - .SetHeader("Content-Type", "application/json") + .WithHeader("Authorization", $"Bearer {_apiKey}") .PostJsonAsync(requestBody) .ReceiveString(); @@ -147,7 +146,7 @@ Reply with ONLY valid JSON, no markdown: } catch (FlurlHttpException httpEx) { - Console.Error.WriteLine($"[DiagnosticService] HTTP error {httpEx.Response?.StatusCode}: {await httpEx.Response?.GetStringAsync()}"); + Console.Error.WriteLine($"[DiagnosticService] HTTP error {httpEx.StatusCode}: {httpEx.Message}"); return null; } catch (Exception ex)