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

5 c# sqlite dll-reference

我需要阅读特定网站的一些 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();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Pra*_*ose 5

使用 NuGet 添加包

Install-Package System.Data.SQLite
Run Code Online (Sandbox Code Playgroud)

它将下载并添加适当的 SQLite 引用。看起来您正在尝试添加错误的引用。您应该从 SQLLite 二进制文件中添加对像 Core / EF6 / Linq 这样的二进制文件的引用。