From 161f6e996cfd4d8cd9b0fd3ea31ef14b22816b84 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 13 Mar 2026 01:35:43 +0000 Subject: [PATCH 1/4] fix: replace assertions with descriptive exceptions in findTypeInfoBySqlEngineTypeId Closes #354 Replace the cryptic assert/Seq.exactlyOne pattern in findTypeInfoBySqlEngineTypeId and findTypeInfoByProviderType with proper exceptions that include actionable diagnostic messages. This helps developers understand the cache invalidation race condition described in issue #354 instead of seeing an opaque assertion failure or 'Sequence contains no elements' error. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../SqlClientExtensions.fs | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/SqlClient.DesignTime/SqlClientExtensions.fs b/src/SqlClient.DesignTime/SqlClientExtensions.fs index 06e5a8f4..530da93c 100644 --- a/src/SqlClient.DesignTime/SqlClientExtensions.fs +++ b/src/SqlClient.DesignTime/SqlClientExtensions.fs @@ -57,19 +57,40 @@ type internal TypeInfoPerConnectionStringCache() = let internal sqlDataTypesCache = new TypeInfoPerConnectionStringCache() let internal findTypeInfoBySqlEngineTypeId (connStr, system_type_id, user_type_id : int option) = - assert (sqlDataTypesCache.ContainsConnectionString connStr) - - sqlDataTypesCache.GetTypesForConnectionString connStr - |> Array.filter(fun x -> - let result = + if not (sqlDataTypesCache.ContainsConnectionString connStr) then + failwithf + "Type info cache does not contain an entry for connection string '%s'. \ + This may be caused by a cache invalidation race — try reloading the project. \ + See https://github.com/fsprojects/FSharp.Data.SqlClient/issues/354" + connStr + + let matches = + sqlDataTypesCache.GetTypesForConnectionString connStr + |> Array.filter (fun x -> x.SqlEngineTypeId = system_type_id && - (user_type_id.IsSome && x.UserTypeId = user_type_id.Value || user_type_id.IsNone && x.UserTypeId = int system_type_id) - result - ) - |> Seq.exactlyOne + (user_type_id.IsSome && x.UserTypeId = user_type_id.Value + || user_type_id.IsNone && x.UserTypeId = int system_type_id)) + + match matches with + | [| single |] -> single + | [||] -> + failwithf + "No SQL type found in cache for SqlEngineTypeId=%d, UserTypeId=%A. \ + This may be caused by a cache invalidation race — try reloading the project. \ + See https://github.com/fsprojects/FSharp.Data.SqlClient/issues/354" + system_type_id user_type_id + | multiple -> + failwithf + "Ambiguous SQL type: %d matches found for SqlEngineTypeId=%d, UserTypeId=%A: %A" + multiple.Length system_type_id user_type_id [| for t in multiple -> t.TypeName |] let internal findTypeInfoByProviderType(connStr, sqlDbType) = - assert (sqlDataTypesCache.ContainsConnectionString connStr) + if not (sqlDataTypesCache.ContainsConnectionString connStr) then + failwithf + "Type info cache does not contain an entry for connection string '%s'. \ + This may be caused by a cache invalidation race — try reloading the project. \ + See https://github.com/fsprojects/FSharp.Data.SqlClient/issues/354" + connStr sqlDataTypesCache.GetTypesForConnectionString connStr |> Array.find (fun x -> x.SqlDbType = sqlDbType) From 37f7b3f5a5aabc06791457ae92eb65c715d0a2ff Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 13 Mar 2026 01:44:25 +0000 Subject: [PATCH 2/4] ci: trigger checks From 0bfd88db0d60ab013fae0b5215bf09fb0bef46f7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 13 Mar 2026 07:17:26 +0000 Subject: [PATCH 3/4] ci: update build script target framework from net6.0 to net8.0 The GitHub Actions Windows runner no longer ships .NET 6 (only 8, 9, 10). This change mirrors PR #461 to allow CI to at least reach the build stage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- build/build.fsproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build.fsproj b/build/build.fsproj index 3686fb1a..5b2f053e 100644 --- a/build/build.fsproj +++ b/build/build.fsproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 From 5042e0732bfa99716b15fc1c1619ea778f41a2a7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 13 Mar 2026 07:30:23 +0000 Subject: [PATCH 4/4] ci: trigger checks