title: SQLite dll for x86/x64 architectures
body: <p>I am developing a program in VB.net, and using <a href="http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki">System.Data.SQLite</a> Precompiled Binaries for .NET, However It is not working for x64 Architectures, and I am getting the classic culture problem and not loading correct file.</p>
  
  <pre><code>System.BadImageFormatException: 
  Could not load file or assembly 'System.Data.SQLite, Version=1.0.65.0, Culture=neutral,
   PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format.
  File name: 'System.Data.SQLite,
   Version=1.0.65.0,
   Culture=neutral, 
   PublicKeyToken=db937bc2d44ff139'
  </code></pre>
  
  <p>Is there a way to use only one dll, maybe:</p>
  
  <ol>
  <li>Add some directives like <strong>#IFDEF</strong> (x86 include some part of code) or else x64 code</li>
  <li>Join dlls to make only one.</li>
  <li>Reference this dll in VB.net</li>
  </ol>
  
  <p>Do you think is other better Idea, as I would like to make only one compilation, not one for x32 and other for x64.</p>
  
  <p>For instance (32 bits):</p>
  
  <pre class="lang-vb prettyprint-override"><code>Private Shared Sub OpenConection(ByRef Conn As SQLite.SQLiteConnection)
      Conn = New SQLite.SQLiteConnection("Data Source=" &amp; System.Environment.CurrentDirectory &amp; "\database.db")
      Conn.Open()
  End Sub
  
  Private Shared Sub CloseConection(ByRef Conn As SQLite.SQLiteConnection)
      Conn.Close()
      Conn.Dispose()
      Conn = Nothing
  End Sub
  
  Public Shared Function ReturnSelect(ByVal DataTAbleName As String, ByVal sQuery As String, ByVal sWhere As String) As Data.DataTable
      Dim lDT As New DataTable
      Dim lTA As New SQLite.SQLiteDataAdapter
      If DataTAbleName Is Nothing Then Return New DataTable(DataTAbleName)
      Try
          OpenConection(conexion)
          lTA = New SQLite.SQLiteDataAdapter("SELECT " &amp; sQuery &amp; " FROM  " &amp; DataTAbleName &amp; IIf(sWhere &lt;&gt; String.Empty, " WHERE ", "") &amp; sWhere, conexion)
          lTA.Fill(lDT)
      Catch ex As Exception
          Throw ex
      Finally
          CloseConection(conexion)
          lTA.Dispose()
          lTA = Nothing
      End Try
      Return lDT
  End Function
  </code></pre>
  
  <p>How to change that to work on 64 bit architecture?
  Maybe including both 32 and 64 dll's and in functions  do something like</p>
  
  <pre class="lang-vb prettyprint-override"><code>Try
      Instance = Me
      'Check If Homidom Run in 32 or 64 bits
      If IntPtr.Size = 8 Then _OsPlatForm = "64" Else _OsPlatForm = "32"
      'continue code
  
  Catch ex As Exception
      ' ex.Message
  End Try
  </code></pre>