Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

System.AppDomainUnloadedException when running UnitTests with RC2 #203

Closed
@divega

Description

@divega

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 other DBContext 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

Error Message:
   Test method xxx.ServiceTests.CleanupSuggestedTest threw exception: 
System.AppDomainUnloadedException: Attempted to access an unloaded AppDomain.
Stack Trace:
    at System.Runtime.Remoting.ObjectHandle.Unwrap()
   at Microsoft.Extensions.Caching.Memory.CacheEntryHelper.get_Scopes()
   at Microsoft.Extensions.Caching.Memory.CacheEntryHelper.EnterScope(CacheEntry entry)
   at Microsoft.Extensions.Caching.Memory.MemoryCache.CreateEntry(Object key)
   at Microsoft.Extensions.Caching.Memory.CacheExtensions.Set[TItem](IMemoryCache cache, Object key, TItem value)
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddAsyncQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
   at yyy.SomeService.<SavePackage>d__6.MoveNext() in C:\Build\_work\22\s\<Project>\Services\SomeService.cs:line 56
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at xxx.ServiceTests.<CleanupSuggestedTest>d__1.MoveNext() in C:\Build\_work\22\s\<Project>.Tests\ServiceTests.cs:line 75
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)

Copied from original issue: dotnet/efcore#5643

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions