64Bit executing

Jul 9, 2011 at 6:07 PM

With 64bit you need to copy the x64 System.Data.SQLite.dll into to the application directory.

 

Since I'm working on the source level I had to change the source code a bit:

  [STAThread]
        static void Main(string[] args)
        {
            LoadSQLLiteAssembly();
           
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //args = new string[] { @"C:\Users\Agus Kurniawan\Documents\PECollege\indihiang\Sample Log\ex081221.log" };          
            if (args.Length >= 1)
                Application.Run(new LightIndihiangForm(args[0]));
            else
                Application.Run(new MainForm());
          
 
            Application.ThreadException += Application_ThreadException;
        }

    private static void LoadSQLLiteAssembly()
        {
            var dir = new Uri(Assembly.GetExecutingAssembly().CodeBase);
            var fi = new FileInfo(dir.AbsolutePath);

            if(!File.Exists(fi.DirectoryName + "\\System.Data.SQLite.dll"))
            {
                File.Copy(fi.DirectoryName + GetAppropriateSQLLiteAssembly(), fi.DirectoryName + "\\System.Data.SQLite.dll");
                Assembly.LoadFrom("System.Data.SQLite.dll");
            }
        }

        private static string GetAppropriateSQLLiteAssembly()
        {
            var architecture = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
            var arch = ((String.IsNullOrEmpty(architecture) || String.Compare(architecture, 0, "x86", 0, 3, true) == 0) ? "32" : "64");
            return "\\" + arch + "\\System.Data.SQLite.DLL";
        }

 

 

And created two folders into Debug folder [32] and [64], at the end I'll create a post build event. For now is good like it is.

Hope it helps someone else.

 

visit my blog: http://www.ruilima.com