View Ticket
Not logged in
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:
The new logging code in 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?)

anonymous added on 2011-10-04 04:20:23 UTC:
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.

mistachkin added on 2011-10-04 04:42:03 UTC:
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.

mistachkin added on 2011-10-04 08:10:08 UTC:
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.