【发布时间】:2017-09-02 15:19:11
【问题描述】:
我有问题。我正在为 iOS 和 Android 应用程序使用 Xamarin。但是当我尝试建立与文件夹路径的连接时,它总是会引发异常。这是我的代码: 公共类查询 { 私有字符串文件夹 = DependencyService.Get().GetAppDataFolder();
public bool createDataBase()
{
try
{
using (var connection = new SQLiteConnection(Path.Combine(folder, "Test.db")))
{
connection.CreateTable<Posten>();
return true;
}
}
catch (SQLiteException ex)
{
System.Diagnostics.Debug.WriteLine("SQLiteEx", ex.Message);
return false;
}
}
}
在使用中抛出异常。我使用 DependencyService 来获取我想要放置数据库的路径。
private string folder = DependencyService.Get<IFileSystemService>().GetAppDataFolder();
在 android 端(我目前正在测试 android)我已经这样实现它:
public class FileSystemServiceAndroid : IFileSystemService
{
public string GetAppDataFolder()
{
return System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
}
}
这就是异常所说的:
未处理的异常:
System.TypeInitializationException:>'SQLite.SQLiteConnection' 的类型初始化程序引发了异常。发生了
我刚刚将我尝试访问 createDataBase 方法的代码移到了我的工具栏的初始化位置,并且我在应用程序中得到了一个消息框:
【问题讨论】:
-
异常怎么说?
-
什么时候出现异常?在构建或运行时?
-
就在我在设备上部署它的运行时
-
您能否从调试输出中提供更多有关异常的详细信息?
-
你使用哪个 sqlite 包?
标签: c# sqlite xamarin xamarin.ios xamarin.android