Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,37 @@ 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.
}
Comment thread
AndriySvyryd marked this conversation as resolved.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it's a TargetInvocationException you still need to filter on the InnerException. Also above, for .Current

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.
}
}
}
Expand Down
Loading