System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
Ticket Hash: ac47dd230ae846e0f3d566a6f9c3d9dd89ffade5
Title: Not Compatible with MSTest (concurrent App Domains)
Status: Closed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Logging Resolution: Fixed
Last Modified: 2011-10-04 09:19:54
Version Found In: 1.0.75.0
Description:
The new logging code in 1.0.75.0 seems to be causing (me) problems when using SQLite from within MSTest.

I think the problem is related to MSTest's usage of multiple App Domains (one per assembly containing unit tests).

SQLiteLog.Initialize is getting a SQLITE_MISUSE error when it tries to set the log callback function.  From what I can tell looking at the SQLite source, the most likely cause of that is that the native library has been initialized (and not fully shutdown?)

<hr /><i>anonymous added on 2011-10-04 04:20:23 UTC:</i><br />
Did some more debugging, and FWIW, the problem appears to be that MSTest isn't shutting down the first app domain before starting tests in the second one.

Not sure if this is fixable within the SQLite library.

A workaround would be to call new SQLiteConnection().Shutdown() in an AssemblyInitialize method, except that won't work because the SQLiteConnection constructor will fail in the SQLiteLog initialization before the Shutdown call can be made.

<hr /><i>mistachkin added on 2011-10-04 04:42:03 UTC:</i><br />
Since AppDomains are totally isolated from each other (i.e. they have no knowledge of each other), this is going to be difficult to solve in managed code.

<hr /><i>mistachkin added on 2011-10-04 08:10:08 UTC:</i><br />
Fixed by check-in [3054af47e2].

Basically, the "fix" for this is to prevent the SQLiteLog class from being initialized in non-default AppDomains unless the special environment variable "Force_SQLiteLog" is set to manually override this new behavior.  This is not an ideal fix; however, it seems reasonable and it is the best that can done without having a reference counting mechanism in the SQLite core library itself.