gpt4 book ai didi

c# - 添加对 SQLite.Interop.dll 的引用时出错

转载 作者:行者123 更新时间:2023-11-30 17:41:00 26 4
gpt4 key购买 nike

我需要读取特定站点的一些 cookie,并且我在 Internet 上找到了一个代码,可能对我有帮助。这段代码使用了一些 SQLite 的特定方法,为了使它有必要添加对一些 SQLite dll 的引用,但问题是,当我去添加 SQlite.Interop.dll 时,这会产生一个错误,指出:

A reference to 'C:\Program Files\System.Data.SQLite\2012\bin\SQLite.Interop.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

enter image description here

所以,有人可以帮我解决这个麻烦。我已经在互联网上的几个网站上看到了与它相关的东西,但直到现在,我还没有成功。

这是我找到的代码,他需要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# - 添加对 SQLite.Interop.dll 的引用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33632471/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com