1

I've created a very simple console app in .NET 4.0 that will run as a scheduled task. It looks for local files that are unmodified for a certain amount of time and then parses the file, inserts a record into a MySQL database, and copies the file to the network. I'm using a local SQLite database to track which files have already been processed, but unfortunately I'm running into a problem on one system at the first SQLite operation:

System.BadImageFormatException: Could not load file or assembly 'System.Data.SQLite.dll' or one of its dependencies.  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1) File name: 'System.Data.SQLite.dll'
at FileDatabase.CreateDatabaseAndTable()
at Program.Main(String[] args)

This exception is thrown on one system (Windows 7 x64 Home Premium with .NET 4.0 full), but is not thrown on two other systems (dev system + one other, both Windows 7 x64 Professional with .NET 4.0 full).

From browsing other questions, I see that this can happen when the program is run in 64-bit mode since the SQLite DLL is the 32-bit version. The first thing I checked is that the active platform is x86 in the Visual Studio Configuration Manager. I also used IL DASM to verify that the output exe is 32-bit (.corflags 0x00000003 // ILONLY 32BITREQUIRED). I would prefer to keep the 32-bit SQLite DLL and target platform as x86 so that I do not have to make different versions of the application for 32- and 64-bit computers.

I've also read that this exception can occur because of a corrupted DLL file, but since it works on some computers, I think this is not the case.

Other things I've tried on the problem system that didn't help:

  • Searching the GAC and Windows directory for errant SQLite DLLs, but found none.
  • Turning off AVG anti-virus.
  • Running the exe directly instead of the published ClickOnce application.
  • Uninstalling and reinstalling the ClickOnce application.

Any suggestions would be appreciated - thanks!

chrisfez
  • 63
  • 2
  • 9
  • You don't say that, but I suppose you have already tried to replace the Sqlite.dll on the broken system. right? – Steve Jan 15 '13 at 18:51
  • @Steve Yes, I've uninstalled and reinstalled the ClickOnce application as well as run directly from the exe copied locally with the DLLs in the same directory. – chrisfez Jan 15 '13 at 18:55
  • Duplication: [What causes System.BadImageFormatException when constructing System.Data.SQLite.SQLiteConnection](http://stackoverflow.com/questions/2048914/what-causes-system-badimageformatexception-when-constructing-system-data-sqlite) – RoadBump Jan 17 '13 at 18:35
  • @RoadBump While the problem is the same, the fix is not - I have already tried the answer in the referenced question without success (see 3rd paragraph). – chrisfez Jan 17 '13 at 18:41
  • Maybe c++ redist isn't installed correctly. I remember that it was mentioned in a question, but can't find it now. Try to use the vendor's installer instead of just copying the dll. – RoadBump Jan 17 '13 at 18:54
  • @RoadBump Installing the full setup package from http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki seems to have solved the problem - it must have been some dependency that was not present (possibly in Windows 7 Professional but not Home?). While this solution isn't perfect for a big deployment, I really just needed it on this one computer so it's fine with me. If you make your comment an answer, I'll accept it. Thanks! – chrisfez Jan 18 '13 at 01:40

1 Answers1

1

Installing the full setup package from system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki seems to have solved the problem - it must have been some dependency that was not present (possibly in Windows 7 Professional but not Home?). While this solution isn't perfect for a big deployment, I really just needed it on this one computer. Thanks for RoadBump for getting me on the right path.

chrisfez
  • 63
  • 2
  • 9