System.IO.FileLoadException: Could not load file or assembly 'System.Data.SQLite

15

(This is a duplicated question which has been asked in stackoverflow.com. I have read the answers. I've tried the solutions, but that didn't solve my problem. I'm going to explain what my problem is and what have I done).

This is my problem:

My application used System.Data.SQLite.DLL. I referenced it and run normally in my computer, but it failed to run on another computer. This is the error message:

System.IO.FileLoadException: Could not load file or assembly 'System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The application has failed to start because its side-by-side
configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
(Exception from HRESULT: 0x800736B1) File name: 'System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' ---> System.Runtime.InteropServices.COMException (0x800736B1): The application has failed to start because its side-by-side
configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
(Exception from HRESULT: 0x800736B1) at SimPB.config.PrepareDatabase() at SimPB.config.InitializeProgram() at SimPB.Program.Main()

My computer is running Windows 7 32 bit, Visual Studio 2010.

Another computer is running Windows 7 32 bit too, without Visual Studio installed.

What I have tried:

Attempt 1: Make sure the application is build with Release + x86 and the application is build with the target framework: .NET Framework 2.0. Done.

Attempt 2: Make sure the application referenced with the correct build of System.Data.SQLite, which is x86 + .Net Framework 2.0 (sqlite-netFx20-binary-Win32-2005-1.0.88.0). Done

Attempt 3: Try these codes at App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

and this

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v2.0.50727"/>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
  <runtime>
    <NetFx40_LegacySecurityPolicy enabled="true"/>
  </runtime>
</configuration>

and this

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v2.0.50727"/>
  </startup>
</configuration>

Done.

Attempt 4: Try turn off User Account Control on the another computer. Done.

Attempt 5: Try install Visual C++ Runtime on the another computer (I install Visual Microsoft Visual C++ Runtime 2010 Redistributable Package (x86), also tried 2005 verson.). Done.

Attempt 6: Try reinstall .NET Framework 2.0 SP2. Receive error:

You must use "Turn Windows Features On or Off" in the Control Panel to install or configure Microsoft .NET Framework 2.0 SP2.

Updated: (After reading answers and comments)
Attempt 7: Make sure System.Data.SQLite.DLL is located at the output bin folder. Done

Attempt 8: Double confirm that the another computer is running 32bit Windows 7. Done

Attempt 9: Change the HintPath declaration in .csproj file:
Change this:

<Reference Include="System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
  <HintPath>E:\Developer Soft\SQLite\sqlite-netFx20-binary-bundle-Win32-2005-1.0.88.0\System.Data.SQLite.dll</HintPath>
</Reference>

To this:

<Reference Include="System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
  <HintPath>..\System.Data.SQLite.dll</HintPath>
</Reference>

Done for Attempt 9.

After the above attempts, the result is still the same. The application can run from my computer normally and failed to run on the another computer.

This is an open source freeware, Simple Phone Book. I have committed and uploaded the latest source code to it's source control server at:
http://simpb.codeplex.com/SourceControl/list/changesets (Changeset Number: fd847ac6c406)

c#
winforms
system.data.sqlite
asked on Stack Overflow Aug 12, 2013 by mjb • edited Apr 15, 2017 by halfer

5 Answers

9

I have solved the problem. This is how I solve:

Short story:
Use older version of System.Data.SQLite. New version is suspected to have bugs (I could be wrong).

Long story:
I started to recall back why my previous old version of this program is able to be executed on other computer and this new version can't. What are the obvious changes that I have made?

Yes, I have changed the version of System.Data.SQLite.

The old version of System.Data.SQLite used by this program is V1.0.66. The new version that I used is the latest version: V1.0.88, released on 8 August 2013. (Yes, which is about 4 days ago from today). Read more: http://system.data.sqlite.org/index.html/timeline

Then I decided to abondon the new version (V1.0.88) and used the old version (V1.0.66), and everything back to normal. The program is once again executable on another computer.

I have tried to have a look at the source code of V1.0.88, but I failed to locate the lines of code which causes the problem. The best I can discovered is at the project of System.Data.SQLite.Interop. When I load the solution in Visual Studio 2010, System.Data.SQLite.Interop is preset to build for .NET Framework 4.0. I don't know how to change it. Later, I reload the solution in Visual Studio 2008, the common properties of System.Data.SQLite.Interop showing that it is going to build for .NET Framework 2.0 (which is what I'm looking for), but I fail to build the solution. Some build errors occur. I didn't spend the time to debug it.

I need to develop the program for .NET Framework 2.0, because there are users who are still using Windows XP.

I assume that V1.0.88 contains bugs, but I could be wrong. Anyway, as for current solution, I just stick to V1.0.66.

answered on Stack Overflow Aug 12, 2013 by mjb • edited Apr 15, 2017 by halfer
7

The assembly cannot be located due to a HintPath declaration in your .csproj file:

<Reference Include="System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
  <HintPath>E:\Developer Soft\SQLite\sqlite-netFx20-binary-bundle-Win32-2005-1.0.88.0\System.Data.SQLite.dll</HintPath>
</Reference>

It works on your machine, because you really have the .dll at that location. However, the other person may want to use the System.Data.SQLite.dll file you placed in the root of the repository. Since that is one level up from the .csproj, you can use a relative path, like this:

<Reference Include="System.Data.SQLite, Version=1.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
  <HintPath>..\System.Data.SQLite.dll</HintPath>
</Reference>

and it should work fine.

answered on Stack Overflow Aug 12, 2013 by Cristian Lupascu
1

I also have had problems with SQLite since v1.0.66 in x64/x86 machines. I have never been able to install ServiceStack and then SqLite.x86 with the nuget package and have it working out of the box.

But today I have changed the installing process with succes, and it might be a solution also for you. I suspect that the problem is allways that the version of System.Data.SQlite is not aligned with the one Servicestack.Ormlite.SqliteNET expects.

The next process in Nuget console makes things work for me:

Install-Package System.Data.Sqlite.x86 -Version 1.0.88.0
Install-Package ServiceStack -Version 3.9.71
Install-Package ServiceStack.OrmLite.Sqlite32 -Version 3.9.71
answered on Stack Overflow Feb 6, 2014 by jruizaranguren • edited Feb 6, 2014 by jruizaranguren
1

In your App.config file, add these lines inside the <configuration> element:
<runtime> <loadFromRemoteSources enabled="true"/> </runtime>

answered on Stack Overflow Apr 2, 2015 by Coder1224
0

Check if MS Visual C++ running redistributable install, as System.Data.SQLite is depend on it.

answered on Stack Overflow Dec 8, 2014 by Leng Weh Seng

User contributions licensed under CC BY-SA 3.0