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
13 changes: 11 additions & 2 deletions src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ static SqliteConnection()
{
currentAppData = appDataType?.GetRuntimeProperty("Current")?.GetValue(null);
}
catch (TargetInvocationException)
catch (TargetInvocationException ex) when (IsNoPackageIdentityException(ex.InnerException))
{
// Ignore "The process has no package identity."
// Ignore the unpackaged-app "no package identity" case; ApplicationData.Current is unavailable there.
}
catch (InvalidOperationException ex) when (IsNoPackageIdentityException(ex))
{
Comment thread
AndriySvyryd marked this conversation as resolved.
// Ignore the unpackaged-app "no package identity" case; ApplicationData.Current is unavailable there.
}

if (currentAppData != null)
Expand All @@ -104,6 +108,11 @@ static SqliteConnection()
}
}

private static bool IsNoPackageIdentityException(Exception? ex)
=> (ex is InvalidOperationException or COMException)
&& (ex.HResult == unchecked((int)0x80073D54) // APPMODEL_ERROR_NO_PACKAGE
|| ex.HResult == unchecked((int)0x8000000D)); // E_ILLEGAL_STATE_CHANGE

/// <summary>
/// Initializes a new instance of the <see cref="SqliteConnection" /> class.
/// </summary>
Expand Down
Loading