我正在 VB.net 中开发一个程序,并使用System.Data.SQLite Precompiled Binaries for .NET,但是它不适用于 x64 架构,并且我遇到了经典的文化问题并且没有加载正确的文件。
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'
有没有办法只使用一个dll,也许:
- 添加一些指令,如#IFDEF(x86 包含部分代码)或 x64 代码
- 加入 dll 只制作一个。
- 在 VB.net 中引用这个 dll
你认为是其他更好的想法吗,因为我只想编译一个,而不是一个用于 x32 和另一个用于 x64。
例如(32 位):
Private Shared Sub OpenConection(ByRef Conn As SQLite.SQLiteConnection)
Conn = New SQLite.SQLiteConnection("Data Source=" & System.Environment.CurrentDirectory & "\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 " & sQuery & " FROM " & DataTAbleName & IIf(sWhere <> String.Empty, " WHERE ", "") & sWhere, conexion)
lTA.Fill(lDT)
Catch ex As Exception
Throw ex
Finally
CloseConection(conexion)
lTA.Dispose()
lTA = Nothing
End Try
Return lDT
End Function
如何将其更改为适用于 64 位架构?也许包括 32 和 64 dll 和函数做类似
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