user5329618
user5329618

Reputation:

Error on add reference to SQLite.Interop.dll

I'm needing read some cookies of a specific site and I found a code on internet that probably can help me. This code uses some methods specifics of SQLite and for make this is necessary add references to some SQLite dlls, but the trouble is, when I will go add SQlite.Interop.dll, this generates a error that says:

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

So, someone can help me to solve this trouble. I already saw in several sites on internet somethings relative to it but until now, I don't had sucess.

This is code that I found, and he have need of SQLite dll file reference, like I said above.

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();
        }
    }
}

Upvotes: 6

Views: 7629

Answers (2)

user3683619
user3683619

Reputation: 21

I had the same error and I was able to resolve it with the following steps:

  1. Go to the location (i.e) "C:\Program Files\System.Data.SQLite\2015\bin" and you will see SQLite.Interop.dll and SQLite.Interop

  2. Copy these two files and then go to the your application bin location (i.e) "........\SQliteExample\SQliteExample\bin\Debug" and paste them there.

Upvotes: -3

Praveen Paulose
Praveen Paulose

Reputation: 5771

Add the package using NuGet

Install-Package System.Data.SQLite

It will download and add the appropriate references for SQLite. It looks like you are trying to add the wrong references. You should be adding references to binaries like the Core / EF6 / Linq from the SQLLite binaries.

Upvotes: 5

Related Questions