Catch InvalidOperationException for unpackaged WinUI3 apps in SqliteConnection#38304
Open
Copilot wants to merge 3 commits into
Open
Catch InvalidOperationException for unpackaged WinUI3 apps in SqliteConnection#38304Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
…ity" error Fixes #38275 - WinRT projection throws InvalidOperationException directly instead of wrapping it in TargetInvocationException when the app has no package identity. Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/bd1535ea-8555-48e5-88dc-23eed99f4c42 Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
AndriySvyryd
May 21, 2026 00:46
View session
There was a problem hiding this comment.
Pull request overview
This PR updates Microsoft.Data.Sqlite’s Windows-specific initialization logic to avoid failing in unpackaged WinUI3 apps where Windows.Storage.ApplicationData.Current can throw InvalidOperationException directly (via CsWinRT), rather than being wrapped in TargetInvocationException.
Changes:
- Add a
catch (InvalidOperationException)alongside the existingcatch (TargetInvocationException)when accessingApplicationData.CurrentinSqliteConnection’s static constructor.
Instead of catching all TargetInvocationException/InvalidOperationException, now uses exception filters that verify the exception is specifically about missing package identity by checking for known HResult values: - 0x80073D54 (APPMODEL_ERROR_NO_PACKAGE) - 0x8000000D (E_ILLEGAL_STATE_CHANGE) Agent-Logs-Url: https://github.com/dotnet/efcore/sessions/699fa5d7-3634-4c58-9596-27949bf0894f Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Windows.Storage.ApplicationData.CurrentthrowsInvalidOperationExceptiondirectly via the CsWinRT projection in unpackaged WinUI3 apps, bypassing theTargetInvocationExceptionwrapper that pure reflection would produce.catch (InvalidOperationException)alongside the existingcatch (TargetInvocationException)in theSqliteConnectionstatic constructorIsNoPackageIdentityExceptionhelper to avoid masking unrelated failures:InvalidOperationExceptionorCOMException0x80073D54(APPMODEL_ERROR_NO_PACKAGE) and0x8000000D(E_ILLEGAL_STATE_CHANGE)TargetInvocationException, validates theInnerExceptiontype and HResult