3

I had to switch from .net 4.5 to .net 4.0 because some of my customers still use WinXP. Now, after switching, this is the error I'm getting:

Could not load file or assembly 'System.Data.SQLite, 
Version=1.0.66.0, Culturre-neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies.  
An attempt was made to load a program with an incorrect format.

I haven't been able to find a solution for this, but here's what I tried so far:

  1. Switch back to 4.5 - Didn't work
  2. Add the reference again - Didn't work

Anyone know a solution?

Matt
  • 41,216
  • 30
  • 109
  • 147
StefanDorresteijn
  • 409
  • 1
  • 5
  • 10
  • 1
    Something like target problem, i.e. your build configuration may be switched to AnyCPU but only x86 available for `System.Data.SQLite`. Possible duplicate: http://stackoverflow.com/questions/2048914/what-causes-system-badimageformatexception-when-constructing-system-data-sqlite – Alvin Wong Nov 21 '12 at 15:01
  • Switching back and forth between CPU configs doesn't fix it. Either way, it used to work before switching frameworks. – StefanDorresteijn Nov 21 '12 at 15:04
  • Hi, welcome to StackOverflow. Instead of linking to an image elsewhere, please include all relevant content inside your question (as I have edited it above). Images can also be uploaded and embedded directly. – Matt Nov 21 '12 at 15:17
  • Thanks Matt, I'll keep that in mind next time! – StefanDorresteijn Nov 21 '12 at 15:21

1 Answers1

3

The right way to fix this is to download an updated version of the SQLite library for your target framework from http://system.data.sqlite.org.

The older System.Data.SQLite assembly that you are using is a mixed code assembly that targets .NET 2.0. The default policy under .NET 4 is to not allow such assemblies to load, but you can explicitly allow it for a process by adding something like this into the MyApp.exe.config file:

<?xml version="1.0"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
  </startup>
</configuration>

Note that the change can break other things though.

This StackOverflow question covers similar ground:

Community
  • 1
  • 1
Govert
  • 16,387
  • 4
  • 60
  • 70