0
votes

I am using a C# application to try to connect to a SQLite database. The application uses the library System.Data.Sqlite, version 108. In Visual Studio 2017, my Solution Configuration is Debug, and my Solution Platform is Any CPU. Whenever I build and run the application, I get the following runtime exception:

enter image description here

The exception is unhandled, and the application terminates.

There is, of course, a SQLite.Interop.dll file in my bin\Debug directory. (If there wasn't, the exception would be different.) Specifically, there are two, each in their own subdirectories named x64 and x86. My assumption is that the file in the x86 directory is being used, since the Solution Platform is set to Any CPU. The version of the SQLite.Interop.dll assembly matches that of System.Data.SQLite.dll, being 1.0.108.0.

When I use the following command to interrogate the assemblies:

dumpbin /exports SQLite.Interop.dll

I do find the following line in the output for the x64 version of the assembly:

175   AE 00040750 sqlite3_open_interop

but in the output for the x86 version I do not. Instead, I find this line:

175   26 00037F10 _sqlite3_open_interop@20

which is close, but not a match. So there is indeed no such method as sqlite3_open_interop exposed by the assembly.

I have tried the obvious solution of changing the Solution Platform to x64, but that change leads to another exception (BadImageFormatException) which I don't much want to contend with.

I have tried dropping the reference to System.Data.SQLite and using Nuget to add the most recent version, 1.0.111.0, then cleaning and rebuilding the solution, but all to no effect. The same issue recurs.

Could anyone suggest a solution to this issue? SQLite is widely used, I believe, so I have to think there's a way to work through it.

*Edit1: I tried this project on my home computer, and observed the same difference between the two SQLite.Interop.dll files. The x64 version had a sqlite3_open_interop, while the x86 version had a _sqlite3_open_interop@20. However, the problem did not occur there. So apparently this mangled name "issue" is a red herring. I am still very interested in solving this problem, and would appreciate the assistance of someone who works on System.Data.Sqlite!

1
BadImageFormatException is due to try to loading a non-compatible library, so I belive when you sat Platform to x64, the loaded library was x86. Keep in mind when importing libraries to match their platform. Any CPU is not specifically x86. To set it to x86, Project properties -> Build -> platform target = x86 - Sohaib Jundi
Thanks for the response. I don't know what you mean by "the loaded library was x86". Loaded in memory? Changing the platform was tried between runs of the application, not during. The platform target was definitely set to x64 when the run was made. - Scitosol

1 Answers

0
votes

It turned out the issue was that the assembly was being blocked or disrupted somehow by McAfee Host Intrusion Prevention. The Activity log had the following message:

Attack type: DISA McAfee - Prevent unexpected DLL files from Running in User AppData and ProgramData folders (Sig Id = 7020)

Which is odd because I don't think my program was executing in either such folder; in fact, there are no such folders, as I am looking at the matter. I was able to fix the issue by moving the program to My Documents.

It's also notable that the exception made no hint of interference by a security scanner.

Sigh. I don't know how generally useful this answer is, but I will leave it here. It might help someone. The admins can remove it if they deem appropriate.