如果我们使用Microsoft.EntityFrameworkCore.InMemory进行单元测试,我们将面临asp.net core 2.2的以下异常
例外如下:
System.TypeLoadException: Could not load type 'Microsoft.Extensions.Logging.Abstractions.Internal.NullScope' from assembly 'Microsoft.Extensions.Logging.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Stack Trace:
at Logger.BeginScope[TState](TState state)
at EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
at InMemoryDatabase.CompileAsyncQuery[TResult](QueryModel queryModel)
at CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
at QueryCompiler.ExecuteAsync[TResult](Expression query)
at IAsyncEnumerable<TResult>.GetEnumerator()
at AsyncEnumerable.Aggregate_[TSource,TAccumulate,TResult](IAsyncEnumerable`1 source, TAccumulate seed, Func`3 accumulator, Func`2 resultSelector, CancellationToken cancellationToken) in Aggregate.cs line: 118
答案 0 :(得分:2)
解决了安装Microsoft.EntityFrameworkCore.InMemory
版本2.2.6
的问题。 Microsoft.EntityFrameworkCore.InMemory
版本需要与项目版本保持相同。