-
Notifications
You must be signed in to change notification settings - Fork 217
System.AppDomainUnloadedException when running UnitTests with RC2 #203
Comments
Moving to caching given the contents of the stack. @Tratcher this is the one I told you about. |
Is this running against net451 or CoreCLR? |
AppDomains, must be net451... |
targeting net46 on system with net461 to be precise |
Interesting. When upgrading to RC2, I assume you upgraded xunit too? Looks like something weird's going on with the appdomains which I think xunit uses. |
@muratg Actually it's MSTest I am not running under .NET Core, I am "only" using the framework inside a classic .NET app, tested with traditional MSTest |
@Mertsch You mean a .csproj based project instead of a project.json based one? |
@muratg Exactly. |
I'm seeing the same issue. I have a plain old .NET class library using RC2 which I'm running MSTest tests against. |
Let me add a little more to what I'm seeing. I have about 140 unit tests against several MVC 5 (ASP.NET 4.6) controllers which reference a class library using Entity Framework Core 1.0 RC2. When running the unit tests it gets through about 5 of them before getting the AppDomainUnloadedException. I can then run the failed unit tests and get through another group before getting the exception again. After 3 or 4 attempts they finally complete. Unfortunately in our automated build this will fail our build. This was not happening with the same unit tests under RC1. |
We were able to get past this issue. It seemed that methods on our controllers were asynchronous and the tests were not waiting for the threads to complete before continuing. This wasn't an issue until we upgraded to RC2. I'm not sure why our tests worked before to begin with. Either way, once we waited for the threads to complete this issue went away. |
We have the same issue. When calling DatabaseContext.Set.SingleOrDefault(this IQueryable source, Expression<Func<TSource, bool>> predicate) we get the AppDomainUnloadedException below.
The exception only occurs if tests from DIFFERENT MS TEST PROJECTS are executed within the same test run. Through debugging in [AssemblyInitialize] of the test projects, I see that they are run in different app domains. So maybe when it comes to the next test project your MemoryCache still has references to the previous app domain from the previous test project? Maybe the issue is related to the commit f15fb80, because there this Remoting.ObjectHandle.Unwrap has been introduced.
|
Now I found the root-cause in my case: In my case the following WORKAROUND helps to overcome this limitation: No idea, whether this workaround has other bad side-effects! And of course this should be fixed in Microsoft.Extensions.Caching.Memory.CacheEntryHelper as soon as possible. |
Good job @BrennanConroy fixing this issue! Sadly @vmsgsp workaround does not work for me. I am working with version 1.0.0, do you think that is there a simple and minimalist way to apply the fix in my code base? |
From @Mertsch on June 3, 2016 12:20
After the upgrade from RC1 to RC2 some of my Unit Tests which test against the DB fail with the following exception.
The behavior is reproducible, BUT only happens in a certain combination of tests. So I can't give a direct example as I am unable to find out which combination of my 90 tests causes this.
Fact is each tests runs fine on its own, all ran fine together with RC1, all tests run fine under R# Test runner, TFS (VSTS) / Test in VS show the same behavior.
The line where the test fails is a
DBContext
accessor, but many otherDBContext
operations have been successful before the specific one.Someone else seems to have the same issue
http://stackoverflow.com/questions/37378698/ef-core-rc2-appdomainunloadedexception
I am not using any In-Memory provider, only pure SQL Server
Each Unit Test builds up a completely new DI context, so that nothing is shared between Tests in any (static) way
Copied from original issue: dotnet/efcore#5643
The text was updated successfully, but these errors were encountered: