“SQLite.SQLiteConnection"的类型初始值设定项引发异常 [英] The type initializer for 'SQLite.SQLiteConnection' threw an exception
问题描述
我正在尝试实现 SQLite 的基本用法.我有一个 Button
和一个 EditText
.我想存储 EditText
OnClick
的内容.
I'm trying to implement an incredibly basic use of SQLite. I have a Button
and an EditText
. I want to store the contents of the EditText
OnClick
.
我正在关注这个:https://developer.xamarin.com/guides/android/application_fundamentals/data/part_3_using_sqlite_orm/
和 https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/databases/
我无法通过以下起始代码而不会出现后续错误:var db = new SQLiteConnection (dbPath);
I cannot get passed the following starting code without getting the subsequent errors: var db = new SQLiteConnection (dbPath);
错误:
'SQLite.SQLiteConnection' 的类型初始值设定项引发异常.
The type initializer for 'SQLite.SQLiteConnection' threw an exception.
内部异常:
System.Exception:这是诱饵".您可能需要添加其中之一SQLitePCLRaw.bundle_* nuget 包到您的平台项目.
在 SQLitePCL.Batteries_V2.Init() [0x00000] 中<9baed10c674b49e0b16322f238b8ecc1>:0 在SQLite.SQLiteConnection..cctor() [0x00000] 中/Users/vagrant/git/src/SQLite.cs:169 }
System.Exception: This is the 'bait'. You probably need to add one of the SQLitePCLRaw.bundle_* nuget packages to your platform project.
at SQLitePCL.Batteries_V2.Init () [0x00000] in <9baed10c674b49e0b16322f238b8ecc1>:0 at SQLite.SQLiteConnection..cctor () [0x00000] in /Users/vagrant/git/src/SQLite.cs:169 }
我已经在 PCL 和 Android 项目上安装了 NuGet 包.我看到安装了以下软件包:
I've installed the NuGet package on both PCL and Android projects. I see the following packages installed:
SQLitePCLRaw.provider.e_sqlite3.android
SQLitePCLRaw.lib.e_sqlite3.android
我试过安装:
SQLitePCLRaw.bundle_e_sqlite3
如前所述,代码是最基本的实现:
As mentioned, the code is the most basic implementation possible:
try
{
string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "TestDB-DEV.db3");
var db = new SQLiteConnection(dbPath);
db.CreateTable<PersonName>();
}
我为此花了几天时间并尝试了许多资源,例如:https://forums.xamarin.com/discussion/87289/sqlite-net-pcl-bait-issue 但最终没有成功.
I've spent a couple days on this and tried numerous resources like: https://forums.xamarin.com/discussion/87289/sqlite-net-pcl-bait-issue but ultimately no success.
不幸的是,像它只是有效"、不确定我做了什么"、清理/重建"之类的废话是我见过的唯一答案,例如上一个链接,其他 SO 帖子,例如 Xamarin SQLite这是‘诱饵’"
Unfortunately, nonsense like "it just works", "not sure what I did", "clean/rebuild" are the only answers I've seen, e.g. previous link, other SO posts like Xamarin SQLite "This is the 'bait'"
这是我的 Android 项目的 package.config
:
Here is my package.config
for the Android project:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="sqlite-net-pcl" version="1.4.118" targetFramework="monoandroid60" />
<package id="SQLitePCLRaw.bundle_green" version="1.1.5" targetFramework="monoandroid60" />
<package id="SQLitePCLRaw.core" version="1.1.5" targetFramework="monoandroid60" />
<package id="SQLitePCLRaw.lib.e_sqlite3.android" version="1.1.5" targetFramework="monoandroid60" />
<package id="SQLitePCLRaw.provider.e_sqlite3.android" version="1.1.5" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.Design" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v7.AppCompat" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v7.CardView" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v7.MediaRouter" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid60" />
<package id="Xamarin.Forms" version="2.4.0.282" targetFramework="monoandroid60" />
</packages>
这是 PCL 项目的 package.config:
Here is the package.config for the PCL project:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="sqlite-net-pcl" version="1.4.118" targetFramework="portable45-net45+win8+wpa81" />
<package id="SQLitePCLRaw.bundle_green" version="1.1.5" targetFramework="portable45-net45+win8+wpa81" />
<package id="SQLitePCLRaw.core" version="1.1.5" targetFramework="portable45-net45+win8+wpa81" />
<package id="Xamarin.Forms" version="2.3.4.247" targetFramework="portable45-net45+win8+wpa81" />
</packages>
推荐答案
我讨厌让自己陷入我不知道我是如何修复它"的困境,但这就是发生的事情.我开始清理并复制+粘贴代码并拒绝 Nuget 包,一切正常.也许我最初忽略了一些东西,也许版本不匹配,我不能说.但是,我尝试添加 Trevor 提到的依赖项,但问题仍然存在,所以我认为我没有遗漏任何东西.
I hate to put myself in the "I don't know how I fixed it" boat, but that's what happened. I started clean and copy+pasted the code and repulled Nuget packages and everything just worked. Maybe I overlooked something initially, maybe had a version mismatch, I cannot say. However, I tried adding the dependencies mentioned by Trevor and the problem still existed, so I don't think I was missing anything.
这篇关于“SQLite.SQLiteConnection"的类型初始值设定项引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!