6

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();
        }
    }
}
  • Note that not everyone can see the image showing your error message (EG I am blocked from seeing it where I am right now). So it would be better for everyone if you could include the text of the error message rather than linking to it as an image. Not only will everyone be able to see the error, but the error (and future answers) will also be indexed by google. – Peter M Nov 10 '15 at 14:49
  • @PeterM, I edited my question. –  Nov 10 '15 at 15:09
  • If you're interested, I've added the message @PeterM – ashes999 Nov 10 '15 at 15:50

2 Answers2

5

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.

Praveen Paulose
  • 5,741
  • 1
  • 15
  • 19
  • Your suggestion worked for me, but using the code above, I not have sucess for read cookies of anyone site from Google Chrome, is I put something as `stackoverflow.com`, this "_Additional information: SQL logic error or missing database no such column: stackoverflow.com_". This is normal? –  Nov 10 '15 at 21:48
-3

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.

Tony Hinkle
  • 4,706
  • 7
  • 23
  • 35