0

In a VS2013 .Net4.5.1 x86 solution I have unit tests that instantiate a SQLite connection. Previously (in VS2008) this was accomplished simply by a reference to the System.Data.SQLite dll (1.0.60.0). However this doesn't work in the .Net4.5.1 world.

So, in VS2013 I have used Nuget to install the latest SQLite package into the test project. Now, I can see the packages folder has been installed into the solution root folder, and the test project has a new reference to

System.Data.SQLite ((...\packages\System.Data.SQLite.Core.1.0.98.1\lib\System.SQLite\dll))

However, when I run the tests they fail with the message

"Unable to load SQLite.Interop.dll. The speficied module cannot be found".

I can see that SQLite.Interop.dll isn't present in the test execution folder (TestResults...\Out) which explains the error message, so I've tried adding that file from the ...\packages\System.Data.SQLite.Core.1.0.98.1\build\net451\x86 folder to the test project and making it 'Copy Always', but that doesn't work. it is still missing from the test execution folder.

I also note that installing SQLite into the GAC (which in principle at least might cure the problem) isn't recommended.

Can anyone advise what needs to be done?

TIA

Guanxi
  • 3,103
  • 21
  • 38
haughtonomous
  • 4,602
  • 11
  • 34
  • 52
  • Did you check any of these answers? http://stackoverflow.com/questions/13028069/unable-to-load-dll-sqlite-interop-dll – Derek Van Cuyk Oct 09 '15 at 13:42
  • I tried all those answers today. The one that worked was – haughtonomous Oct 12 '15 at 08:42
  • I tried all those answers today. Most didn't solve the problem at all, but the two steps that collectively that worked are (a) add the Interop dll to the test project, "copy always", then (b) add a DeploymentItem attribute to the classes containing the failing tests, with the DeploymentItem pointing a path to the Interop dll in the solution, relative to the test project root folder. Thanks for the tip. Even though the Nuget package was installed to the correct test project, that was only part of the solution. I guess that particular package is only half written :-) – haughtonomous Oct 12 '15 at 08:48

2 Answers2

0

This might be happen because of Platform dependency. You should attach dll file for SQLite in references. Then after you should attach library for different platforms x86 and x64 both in visual studio. After that there will be two SQLite.Interop.dll file will be create by library for both platforms.

Amit Kumawat
  • 574
  • 5
  • 11
  • "Then after you should attach library for different platforms x86 and x64 both in visual studio." Please elaborate on what you mean by this. – haughtonomous Oct 12 '15 at 08:19
0

I had the same issue with Visual Studio 2017. The issue is related to the way SQLite resolves the interop dependency based on the platform you're targetting. More information can be found in: https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

In order to solve this issue, you need to force the build process to deploy the interop files to the folder where the executable files are. The folder structure must remain the same ".\x86" and ".\x64".

Assuming that you have a folder with your external dependencies in the solution root folder, just place the sqlite interop files there, so you can copy them during the post build event:

-- src/
  -- /External
     -- /sqlite
        -- /x86
        -- /x64

You can include this in your post build action, in the test project:

xcopy /Y /S $(SolutionDir)\External\sqlite\* $(TargetDir)

This will place the folder structure to the output folder of the test project. Please, let us know if this solves your issue. If it doesn't, I can try to explain it better.

UPDATED

You can improve the post-build script by using a conditional copy:

if not exist "$(SolutionDir)\External" (
    xcopy /Y /S $(SolutionDir)\External\sqlite\* $(TargetDir)
)

This it won't run if the x86 and x64 folders were already copied.

Fabricio
  • 532
  • 1
  • 6
  • 21