We are using ODP.NET Managed in a large C# .NET Project. When running tests against the database we get the following exception logged in the Tests Output Window of Visual Studio 2015:
System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain. This can happen if the test(s) started a thread but did not stop it. Make sure that all the threads started by the test(s) are stopped before completion.
We were able to reproduce the error in a separate Visual Studio Unit Test Project with just a single test that opens and closes a connection:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Oracle.ManagedDataAccess.Client;
namespace AppDomainStuff
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
using (var dbConnection = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=EXAMPLE_HOST)(PORT = 1521))(CONNECT_DATA=(SERVICE_NAME=EXAMPLE_SERVICE_NAME)));Persist Security Info=True;User ID=example_user;Password=example_password"))
{
dbConnection.Open();
dbConnection.Close();
}
}
}
}
In order to reproduce the behavior perform the following steps:
- create a new unit-test-project (Target Framework: 4.6.1)
- add a reference to System.Data
- add the nuget package for odp.net managed (version 12.1.24160719) to the project
- replace the content of the file "UnitTest1.cs" with the code above
- build the project
- run the test using MSTest Runner (Menu Test/Run all Tests)
=> you should see the System.AppDomainUnloadedException in the output window.
Is this a (known) issue or are we doing something wrong?
Any help is appreciated.
Kind regards,
Marcel