3

I'm having a heck of a time getting my tests to run against my SQLite Data Provider.

I've looked at the suggested links here on stackoverflow, but none of them seem to get me going down the right path.

I've downloaded the Windows Precompiled Binaries for sqlite3.dll

I've copied the sqlite3.dll into both my Sqlite\bin directory as well as my Tests\bin directory dll copied into bin directories

Unfortunately when I run my tests, I get the following error

failed test

Is there a clear cut way to get this working both in my Windows dev environment (primary goal right now) as well as running in Android and IOS (required in the near future)?

Also, if it matters, here are my Sqlite project references.

enter image description here

Community
  • 1
  • 1
Chase Florell
  • 46,378
  • 57
  • 186
  • 376
  • 2
    It seems to me that the assembly needs to reside in the output directory, not the `bin` directory. – Mike Perrenoud Oct 16 '13 at 20:10
  • You are using 'Copy Local'(dll properties) true? – Jhonatas Kleinkauff Oct 16 '13 at 20:14
  • moving the dll into the bin\debug directory yields a new error `System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)` Looks like it has to do with x86/x64 – Chase Florell Oct 16 '13 at 20:16
  • http://stackoverflow.com/q/4744293/62576 didn't help? – Ken White Oct 16 '13 at 20:20
  • It would appear as though I need to use the `Sqlite.Interop.dll` files, and rename it to `sqlite3.dll`. Now the only problem I'm going to run into is if the build is run on a different platform x8x / x64 – Chase Florell Oct 16 '13 at 20:25
  • Instead of doing this manually, did you try installing SQLite with NuGet? It will add the references and put everything in place, and have both x86 and x64 versions installed. – Noctis Oct 16 '13 at 21:58
  • yes I did, however the file names are incorrect. The tests were originally showing the need for `sqlite3` and nuget pulls down `SQLite.Interop` which you can see in my screenshot above. – Chase Florell Oct 16 '13 at 22:00

4 Answers4

5

So the answer for me was quite simple. I wired up a Pre-Build event that checks the architecture of the machine, and copies the appropriate dll into the output bin directory.

Now anyone on our team can simply run REBUILD, and the proper dll will be available to run against SQLite.

if '$(PROCESSOR_ARCHITECTURE)'=='AMD64' (xcopy /y "$(ProjectDir)x64\sqlite3.dll" ".\") 
if '$(PROCESSOR_ARCHITECTURE)'=='x86' (xcopy /y "$(ProjectDir)x86\sqlite3.dll" ".\")
if '$(PROCESSOR_ARCHITEW6432)'=='AMD64' (xcopy /y "$(ProjectDir)x64\sqlite3.dll" ".\")
Chase Florell
  • 46,378
  • 57
  • 186
  • 376
3

When I add the following libraries the error went away

  1. Microsoft Visual C++ Runtime Package (V11.0)
  2. SQLite for Windows Runtime (V3.8.7.1)

When I add the following libraries the error went away

SurenSaluka
  • 1,534
  • 3
  • 18
  • 36
0

Can't put this in comments, so here's what I got: enter image description here

Also, have a look at Similar problem.

Last, but not least, did you try to add a reference to the SQLite.Inetrop.dll (in the references)? References -> add -> just browse to where your SQLite is, select view all, and add a reference to the Interop.dll as well)

Community
  • 1
  • 1
Noctis
  • 11,507
  • 3
  • 43
  • 82
  • my project can't use the dll's directly from nuget. We're using a different version of Mono.Data.Sqlite, and the sqlite3.dll cannot be referenced in the project as it is not a .net dll. – Chase Florell Oct 19 '13 at 23:40
  • 1
    You cannot add SQLite.Interop.dll with references->add. This is because SQLite.Interop.dll is unmanaged and therefore not valid. – sapbucket Sep 23 '14 at 16:25
0

I am using VS2017 and solved the issue by adding the following task to copy the assembly.

<Target Name="Ensure SQLite assemblies copied" AfterTargets="Build" Condition=" '$(Platform)' == 'x64' ">
  <Copy SourceFiles="$(OutDir)x64\SQLite.Interop.dll" DestinationFolder="$(OutDir)" />
</Target>
Poulad
  • 1,149
  • 1
  • 12
  • 22