【发布时间】:2016-06-10 16:35:48
【问题描述】:
第一次使用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!");
});
}
我从我的 UWP 应用程序中调用 NewspaperDataContext,如下所示:
private async void MainPage_OnLoaded(object sender, RoutedEventArgs e)
{
var n = new NewspaperDataContext(new SQLitePlatformWinRT(), ApplicationData.Current.LocalFolder.Path, "LiberteDB");
}
在 NewspaperDataContext 构造函数中的一行:
var c = _sqlConnection.Table<Article>();
抛出一个奇怪的 MissingMethodException 说:
“System.MissingMethodException”类型的异常发生在 SQLite.Net.Async.dll 但未在用户代码中处理
附加信息:找不到方法:'无效 SQLite.Net.SQLiteConnectionString..ctor(System.String,布尔值, SQLite.Net.IBlobSerializer, SQLite.Net.IContractResolver)'。
在互联网上找不到与此错误相关的任何内容,请有人帮忙。
【问题讨论】:
-
当尝试动态访问不存在的方法时会抛出此异常。我认为问题可能在于您创建了一个必须具有返回类型的方法
NewspaperDataContext,但您的代码中没有返回值。你调用这个方法就像创建一个名为NewspaperDataContext的类的新实例。如果这个方法是 void 类的,你能不能试着用这个代码NewspaperDataContext(new SQLitePlatformWinRT(), ApplicationData.Current.LocalFolder.Path, "LiberteDB");调用这个方法? -
或者,如果有返回值,请您尝试像
var n = NewspaperDataContext(new SQLitePlatformWinRT(), ApplicationData.Current.LocalFolder.Path, "LiberteDB");一样调用这个方法吗?抱歉,如果我误解了您的NewspaperDataContext方法。但我认为问题可能与您如何调用此方法有关。 -
您了解这个问题的根源了吗?我也有类似的问题
-
发现是重新添加了导致我的问题的旧包。 github.com/oysteinkrog/SQLite.Net-PCL/issues/14
标签: c# sqlite win-universal-app portable-class-library sqlite-net