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 <noreply@anthropic.com>
This commit is contained in:
Yinyin Liu 2026-02-12 07:55:43 +01:00
parent 2da2ded84c
commit 0c918e86ae
2 changed files with 6 additions and 9 deletions

View File

@ -1,5 +1,3 @@
using System.Collections.Frozen;
namespace InnovEnergy.App.Backend.Services;
/// <summary>
@ -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<string, DiagnosticResponse> SinexcelAlarms = new Dictionary<string, DiagnosticResponse>
private static readonly IReadOnlyDictionary<string, DiagnosticResponse> SinexcelAlarms = new Dictionary<string, DiagnosticResponse>
{
// 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<string, DiagnosticResponse> GrowattAlarms = new Dictionary<string, DiagnosticResponse>
private static readonly IReadOnlyDictionary<string, DiagnosticResponse> GrowattAlarms = new Dictionary<string, DiagnosticResponse>
{
// 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();
};
}

View File

@ -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)