.NET Maui SQLite 连接

.NET Maui SQLite Connection

我已将 sqlite-net-plc 包添加到我的项目中并创建了一个数据库 class,如下所示:

public class Database
{
    public Database()
    {
        var dbPath = Path.Combine(FileSystem.AppDataDirectory, "databaseTest.db3");

        Connection = new SQLiteAsyncConnection(dbPath);
        Connection.CreateTableAsync<User>().Wait();
    }

    public SQLiteAsyncConnection Connection { get; set; }
}

这似乎适用于 Android 应用程序,允许我从任何地方操作数据库。

但是,当我 运行 通过具有活动 Mac 连接的 IOS 模拟器此应用程序时,我收到以下错误:

The type initializer for 'SQLite.SQLiteConnection' threw an exception.

我认为无法解析与 SQLite 数据库的活动连接,但我不知道为什么。任何对此的见解都会很棒。

提前致谢。

在将 sqlite-net-pcl 添加到库存 MAUI 测试应用程序之后,我在 iOS 和 Android 上都看到了相同的异常,直到我明确添加 https://www.nuget.org/packages/SQLitePCLRaw.bundle_green/2.0.7 打包到项目中。

我看到“原始”包作者在 9 月 7 日指出他有工作要做:https://github.com/ericsink/SQLitePCL.raw/discussions/449#discussioncomment-1282643

sqlite-net-pcl 取决于超过一年的“原始”nuget 版本 2.0.4。也许 2.0.7 修复了与 iOS 相关的问题?我在那个时间段的 https://github.com/ericsink/SQLitePCL.raw/commits/master 看到了一些特定于 Apple 的提交。

也许您已经安装了更新的版本,其中修复了 Android,但没有修复 iOS?

github 上回答的问题:https://github.com/dotnet/maui/issues/3211