SQLite.Interop.dll locked after running Visual Studio 2012 Unit Test Framework tests

c#, dispose, sqlite, unit-testing, visual-studio-2012

Solution

I could not find that option in VS2012 (at least not for standard unit tests), therefore I came up with another solution:

The problem you are facing comes from the fact that the unit test runner remains loaded so that repeated test runs are faster. Since `SQLite.Interop.dll` will probably not change too often, I changed the `CopyToOutputDirectory` option to `PreserveNewest` rather than the default `Always`.

You can do this by opening the properties (F4) view and selecting the `SQLite.Interop.dll` file in your solution. The only time this will probably still lock up is when you upgrade to a newer version of SQLite and restarting VS2012 then works OK for me.

Problem

- Visual Studio 2012 - SQLite 1.0.82.0 (from nuget) I am trying to use the "Run All" command in the "Test Explorer" The following error happens after you run the test once ... after that it will not build anymore, until you restart visual studio Here is the build error The Process cannot access the file 'SQLite.Interop.dll' because it is being used by another process here is the code ``` using System.Data.SQLite; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Test.Sqlite { [TestClass] public class Test_Sqlite_Locking { [TestMethod] public void can_create_table() { using(var fact = new SQLiteFactory()) using (var conn = fact.CreateConnection()) { conn.ConnectionString = "Data Source=:memory:;Version=3;New=True;"; conn.Open(); //conn.Close(); } //SQLiteConnection.ClearAllPools(); //GC.Collect(); } } } ``` I have tried, closing connection, calling ClearAllPools, GC.Collect, and creating the SQLiteConnection directly (instead of the Factory) ... still same issue This DOES work if you DEBUG ALL TESTS ... but it is when you just Run the tests that this seems to lock it up

Original source

Related problems