Question

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!

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top