[英]Error on add reference to SQLite.Interop.dll
我需要閱讀一些特定網站的cookie,我在互聯網上找到了可能對我有幫助的代碼。 這段代碼使用了SQLite的一些特定方法,並且為了使這有必要添加對一些SQLite dll的引用,但問題是,當我要添加SQlite.Interop.dll時,會產生一個錯誤,指出:
無法添加對“C:\\ Program Files \\ System.Data.SQLite \\ 2012 \\ bin \\ SQLite.Interop.dll”的引用。 請確保該文件是可訪問的,並且它是有效的程序集或COM組件。
所以,有人可以幫我解決這個問題。 我已經在互聯網上的幾個網站上看到了相對於它的東西,但直到現在,我還沒有成功。
這是我發現的代碼,他需要SQLite dll文件引用,就像我上面說的那樣。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static public IEnumerable<Tuple<string, string>> ReadCookies(string hostName)
{
if (hostName == null) throw new ArgumentNullException(hostName);
var dbPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Google\Chrome\User Data\Default\Cookies";
if (!System.IO.File.Exists(dbPath)) throw new System.IO.FileNotFoundException("Cant find cookie store", dbPath);
var connectionString = "Data Source=" + dbPath + ";pooling=false";
using (var conn = new System.Data.SQLite.SQLiteConnection(connectionString))
using (var cmd = conn.CreateCommand())
{
var prm = cmd.CreateParameter();
prm.ParameterName = hostName;
prm.Value = hostName;
cmd.Parameters.Add(prm);
cmd.CommandText = "SELECT name,encrypted_value FROM cookies WHERE host_key = " + hostName;
conn.Open();
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var encryptedData = (byte[])reader[1];
var decodedData = System.Security.Cryptography.ProtectedData.Unprotect(encryptedData, null, System.Security.Cryptography.DataProtectionScope.CurrentUser);
var plainText = Encoding.ASCII.GetString(decodedData);
yield return Tuple.Create(reader.GetString(0), plainText);
}
}
conn.Close();
}
}
static void Main(string[] args)
{
var list = ReadCookies("facebook.com");
foreach (var item in list)
Console.WriteLine("{0} | {1}", item.Item1, item.Item2);
Console.WriteLine();
Console.ReadLine();
}
}
}
使用NuGet添加包
Install-Package System.Data.SQLite
它將下載並添加適用於SQLite的引用。 看起來您正在嘗試添加錯誤的引用。 您應該從SQLLite二進制文件中添加對二進制文件的引用,如Core / EF6 / Linq。
我有同樣的錯誤,我能夠通過以下步驟解決它:
轉到位置(即)“C:\\ Program Files \\ System.Data.SQLite \\ 2015 \\ bin”,您將看到SQLite.Interop.dll和SQLite.Interop
復制這兩個文件,然后轉到您的應用程序bin位置(即)“........ \\ SQliteExample \\ SQliteExample \\ bin \\ Debug”並將其粘貼到那里。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.