From 7cb722c396a9a659a75ce9aca8102c1aac26f971 Mon Sep 17 00:00:00 2001 From: Josh Patra Date: Thu, 5 Feb 2026 09:40:39 -0500 Subject: [PATCH] Fix HasValue method to handle JsonElement properly - Changed parameter type from dynamic? to object? to avoid runtime binding issues - Added check for JsonValueKind.Undefined in addition to Null - Fixes crash when checking external mappings that return JsonElement - Applied fix to both AdminController and SpotifyTrackMatchingService --- allstarr/Controllers/AdminController.cs | 4 ++-- allstarr/Services/Spotify/SpotifyTrackMatchingService.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/allstarr/Controllers/AdminController.cs b/allstarr/Controllers/AdminController.cs index b256802..a290b31 100644 --- a/allstarr/Controllers/AdminController.cs +++ b/allstarr/Controllers/AdminController.cs @@ -86,10 +86,10 @@ public class AdminController : ControllerBase /// Helper method to safely check if a dynamic cache result has a value /// Handles the case where JsonElement cannot be compared to null directly /// - private static bool HasValue(dynamic? obj) + private static bool HasValue(object? obj) { if (obj == null) return false; - if (obj is JsonElement jsonEl) return jsonEl.ValueKind != JsonValueKind.Null; + if (obj is JsonElement jsonEl) return jsonEl.ValueKind != JsonValueKind.Null && jsonEl.ValueKind != JsonValueKind.Undefined; return true; } diff --git a/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs b/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs index 611ccb9..dae5f56 100644 --- a/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs +++ b/allstarr/Services/Spotify/SpotifyTrackMatchingService.cs @@ -48,10 +48,10 @@ public class SpotifyTrackMatchingService : BackgroundService /// Helper method to safely check if a dynamic cache result has a value /// Handles the case where JsonElement cannot be compared to null directly /// - private static bool HasValue(dynamic? obj) + private static bool HasValue(object? obj) { if (obj == null) return false; - if (obj is JsonElement jsonEl) return jsonEl.ValueKind != JsonValueKind.Null; + if (obj is JsonElement jsonEl) return jsonEl.ValueKind != JsonValueKind.Null && jsonEl.ValueKind != JsonValueKind.Undefined; return true; }