使用SQLiteAsyncConnection抛出MissingMethodException

Aym*_*udi 5 c# sqlite portable-class-library sqlite-net win-universal-app

第一次使用SQLite,选择了SQLite.net-pcl,

我有一个PCL库,我从我的UWP应用程序中消耗,我的PCL库有DBContext类:

public NewspaperDataContext(ISQLitePlatform sqLitePlatform, string applicationPath, string dataBaseName)
{
     _sqlConnection = new SQLiteAsyncConnection(()=> new SQLiteConnectionWithLock(sqLitePlatform, 
     new SQLite.Net.SQLiteConnectionString(Path.Combine(applicationPath, dataBaseName), storeDateTimeAsTicks: false)));

     CreateTableAsync(_sqlConnection, typeof(Article)).Result.Wait();
     CreateTableAsync(_sqlConnection, typeof(Author)).Result.Wait();
     CreateTableAsync(_sqlConnection, typeof(Category)).Result.Wait();
     CreateTableAsync(_sqlConnection, typeof(Group)).Result.Wait();

     var c = _sqlConnection.Table<Article>();
}

private async Task<Task> CreateTableAsync(SQLiteAsyncConnection asyncConnection, Type table)
{
     return asyncConnection.CreateTableAsync<Author>().ContinueWith((results) =>
     {
           Debug.WriteLine(!results.IsFaulted
           ? $"Error where creating the {nameof(table)} table !!"
           : $"Table {nameof(table)} created sucessfully!");
     });
}
Run Code Online (Sandbox Code Playgroud)

NewspaperDataContext从我的UWP应用程序中调用这样的:

private async void MainPage_OnLoaded(object sender, RoutedEventArgs e)
{            
    var n = new NewspaperDataContext(new SQLitePlatformWinRT(), ApplicationData.Current.LocalFolder.Path, "LiberteDB");
}
Run Code Online (Sandbox Code Playgroud)

在该行的NewspaperDataContext构造函数中:

var c = _sqlConnection.Table<Article>();
Run Code Online (Sandbox Code Playgroud)

抛出一个奇怪的MissingMethodException:

SQLite.Net.Async.dll中出现"System.MissingMethodException"类型的异常但未在用户代码中处理

附加信息:找不到方法:'Void SQLite.Net.SQLiteConnectionString..ctor(System.String,Boolean,SQLite.Net.IBlobSerializer,SQLite.Net.IContractResolver)'.

在互联网上找不到与此错误相关的任何内容,请有人帮忙.

Ram*_*esh 0

该包sqlite-net-pcl应仅添加到 PCL 项目中。如果您将其添加到任何其他平台(例如 Android),它将提供此MethodMissingException. 因此,请从其他平台删除该包,因为仅 PCL 项目需要该包。我给出这个答案是因为我遇到了同样的问题并找到了解决方案。我在使用 Xamarin.Forms 开发应用程序时遇到了此异常。