Search code examples
sqliteexceptionassembliessystem.data.sqlite.net-4.8

Could not load file or assembly 'System.Data.SQLite, Version=1.0.115.5


.NET Framework project - added SQLite to my project via Nuget package, app.config and package.config look correct.

Errors is:- "Type : System.IO.FileNotFoundException, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Message : Could not load file or assembly 'System.Data.SQLite, Version=1.0.115.5, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The system cannot find the file specified."

All projects targeting x86

Packages.config

<packages>
   <package id="EntityFramework" version="6.4.4" targetFramework="net471" />
   <package id="Stub.System.Data.SQLite.Core.NetFramework" version="1.0.115.5" targetFramework="net471" />
   <package id="System.Data.SQLite" version="1.0.115.5" targetFramework="net471" />
   <package id="System.Data.SQLite.Core" version="1.0.115.5" targetFramework="net471" />
   <package id="System.Data.SQLite.EF6" version="1.0.115.5" targetFramework="net471" />
   <package id="System.Data.SQLite.Linq" version="1.0.115.5" targetFramework="net471" />
</packages>

I have tried links below and so many others but nothing working - what am I missing?

Could not load file

Could not load file or assembly 'System.Data.SQLite'

enter image description here


Solution

  • I recently had a similar problem when I upgraded from 1.0.113 to 1.0.115. It appears that the dependent native binaries are not correctly copied any more.

    Adding these two lines to the post build step of a project (doesn't really matter which one in your solution) helped:

    xcopy /s /y "%USERPROFILE%\.nuget\packages\Microsoft.SqlServer.Compact\4.0.8876.1\NativeBinaries\amd64\*.*" "$(TargetDir)"
    xcopy /s /y "%USERPROFILE%\.nuget\packages\Stub.System.Data.SQLite.Core.NetFramework\1.0.115\build\net46\*.dll" "$(TargetDir)"
    

    (Maybe you need to adapt the lines, depending on the package version used and the .NET version targeted)

    EDIT Since you are still using packages.config, the above copy instructions should probably be changed to:

    xcopy /s /y "$(SolutionDir)\packages\Microsoft.SqlServer.Compact\4.0.8876.1\NativeBinaries\amd64\*.*" "$(TargetDir)"
    xcopy /s /y "$(SolutionDir)\packages\Stub.System.Data.SQLite.Core.NetFramework\1.0.115\build\net46\*.dll" "$(TargetDir)"