Skip to content

fix: handle when WinRT APIs are unavailable#38612

Open
BrycensRanch wants to merge 2 commits into
dotnet:mainfrom
BrycensRanch:main
Open

fix: handle when WinRT APIs are unavailable#38612
BrycensRanch wants to merge 2 commits into
dotnet:mainfrom
BrycensRanch:main

Conversation

@BrycensRanch

@BrycensRanch BrycensRanch commented Jul 12, 2026

Copy link
Copy Markdown
  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)

The change is a small addition to an existing exception filter and doesn't introduce new behavior that requires unit testing. The exceptions being added are already handled conceptually by the existing "feature unavailable" logic.

  • Code follows the same patterns and style as existing code in this repo

Motivation

The existing code already catches exceptions from the initial WinRT call (e.g., TargetInvocationException and InvalidOperationException for unpackaged apps). However, Wine partially implements WinRT — it successfully returns a ApplicationData object from the first call, but then throws NotImplementedException when accessing the LocalFolder property. Since this exception isn't caught, the entire SqliteConnection type becomes unusable.

Note: System.Data.SQLite works fine under Wine because it doesn't attempt this WinRT trick. However, I love Microsoft.Data.Sqlite and I'm a programmer that daily drives Linux and want to test my application under Wine instead of an VM. It'd also fix ShareX's latest versions under Wine too.

Fixes #36343

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to make Microsoft.Data.Sqlite more resilient on Windows-like environments where WinRT APIs exist but are partially unavailable (e.g., Wine), by extending the static initialization logic that attempts to use Windows.Storage.ApplicationData.

Changes:

  • Adds exception handling intended to treat NotImplementedException/NotSupportedException as “WinRT feature unavailable” during WinRT probing in SqliteConnection’s static constructor.

Comment thread src/Microsoft.Data.Sqlite.Core/SqliteConnection.cs
@BrycensRanch

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getting exceptions from SqliteConnection static constructor on Windows desktop [OUTDATED] [Guide] Get ShareX up and running on Linux

2 participants