System.Data.SQLite And 64 Bit Operating Systems

An old customer surfaced recently, wondering why a new installation of an old .Net WinForms application I wrote wouldn’t work on their shiny new 64 bit system.

As it turns out, I used SQLite for this particular project as the data storage engine. Because this is a managed .Net wrapper around the native sqlite library, it was causing problems when trying to load the 32 bit version of the library on a 64 bit system.

A Quick Fix

Fortunately it’s quite straight forward to force an assembly to run in a 32 bit version of .Net, regardless of the host platform as there is a flag in the assembly that will define this.

In Visual Studio this can be found on the project properties page under the ‘Build’ tab.

Platform Target

Setting ‘Platform Target’ to x86 will force the assembly to be run under the 32 bit .Net framework.

This can also be set using the command line corflags utility:

corflags /32BIT+ dotnetapp.exe

The Correct Fix

Obviously the correct thing to do would be to detect the OS version on install and use the correct version of the SQLite wrapper, but the above serves as a quick fix to get them up and running.