From 4ef19fa5659a1ca2ff025f2ed70ab4db3438e8de Mon Sep 17 00:00:00 2001 From: Brycen G Date: Sun, 12 Jul 2026 13:50:06 -0400 Subject: [PATCH 1/2] fix: handle when WinRT APIs are unavailable --- src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs index 4e7b17e5bbc..0c32f386782 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs @@ -86,6 +86,11 @@ static SqliteConnection() { // Ignore the unpackaged-app "no package identity" case; ApplicationData.Current is unavailable there. } + catch (Exception ex) when (ex is NotImplementedException or NotSupportedException) + { + // Ignore when WinRT APIs aren't implemented or supported (e.g., running under Wine) + // ApplicationData.Current is unavailable there. + } if (currentAppData != null) { From eb9d8d5210fe2839db9c4fcb2b55a72ef480cc55 Mon Sep 17 00:00:00 2001 From: Brycen G Date: Sun, 12 Jul 2026 15:49:46 -0400 Subject: [PATCH 2/2] fix: handle WinRT failures when accessing LocalFolder/TemporaryFolder --- .../SqliteConnection.cs | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs index 0c32f386782..b83814bf288 100644 --- a/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs +++ b/src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs @@ -94,20 +94,29 @@ static SqliteConnection() if (currentAppData != null) { - var localFolder = appDataType?.GetRuntimeProperty("LocalFolder")?.GetValue(currentAppData); - var localFolderPath = (string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(localFolder); - if (localFolderPath != null) + try { - var rc = sqlite3_win32_set_directory(SQLITE_WIN32_DATA_DIRECTORY_TYPE, localFolderPath); - Debug.Assert(rc == SQLITE_OK); + var localFolder = appDataType?.GetRuntimeProperty("LocalFolder")?.GetValue(currentAppData); + var localFolderPath = (string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(localFolder); + if (localFolderPath != null) + { + var rc = sqlite3_win32_set_directory(SQLITE_WIN32_DATA_DIRECTORY_TYPE, localFolderPath); + Debug.Assert(rc == SQLITE_OK); + } + + var tempFolder = appDataType?.GetRuntimeProperty("TemporaryFolder")?.GetValue(currentAppData); + var tempFolderPath = (string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(tempFolder); + if (tempFolderPath != null) + { + var rc = sqlite3_win32_set_directory(SQLITE_WIN32_TEMP_DIRECTORY_TYPE, tempFolderPath); + Debug.Assert(rc == SQLITE_OK); + } } - - var tempFolder = appDataType?.GetRuntimeProperty("TemporaryFolder")?.GetValue(currentAppData); - var tempFolderPath = (string?)storageFolderType?.GetRuntimeProperty("Path")?.GetValue(tempFolder); - if (tempFolderPath != null) + catch (Exception ex) when (ex is TargetInvocationException + or NotImplementedException + or NotSupportedException) { - var rc = sqlite3_win32_set_directory(SQLITE_WIN32_TEMP_DIRECTORY_TYPE, tempFolderPath); - Debug.Assert(rc == SQLITE_OK); + // Ignore failures accessing LocalFolder/TemporaryFolder when WinRT isn't fully implemented. } } }