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
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.
I worked around this by using the following as a pre-build event on the affected test projects:
for 64-bit:
taskkill /F /IM vstest.executionengine.exe /FI "MEMUSAGE gt 1"
or for 32-bit:
taskkill /F /IM vstest.executionengine.x86.exe /FI "MEMUSAGE gt 1"
This silently kills the execution engine before building the test project. The /FI "MEMUSAGE gt 1"
stops the command (and therefore the build) from failing if the execution engine isn't running.
Try this:
You should be able run SQLite based tests now without having to restart.
In Visual Studio 2013 - Go to "Test > Test Settings > keep Test Execution Engine Runing" and uncheck it! Works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With