保存到Raven时发生异常

时间:2019-01-31 04:33:57

标签: .net-core ravendb asp.net-core-2.1

在一个环境中尝试将实体保存到Raven时出现异常。

以下是详细信息:

应用程序目标框架 :. NET Core 2.1

RavenDB.Client版本:4.1.2

服务器上安装的.Net Core运行时和主机捆绑包

2.0.5

2.1.3

2.1.6

2.2.0

(我们安装了多个版本,因为它是一个托管了多个应用程序的共享环境)

例外

System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Sparrow.Json.UnmanagedWriteBuffer.Write(Byte* buffer, Int32 count)
   at Sparrow.Json.BlittableWriter`1.WriteValue(Byte* buffer, Int32 size, FastList`1 escapePositions, BlittableJsonToken& token, UsageMode mode, Nullable`1 initialCompressedSize) in C:\Builds\RavenDB-Stable-4.1\src\Sparrow\Json\BlittableWriter.cs:line 555
   at Sparrow.Json.BlittableJsonDocumentBuilder.ReadInternal[TWriteStrategy]() in C:\Builds\RavenDB-Stable-4.1\src\Sparrow\Json\BlittableJsonDocumentBuilder.cs:line 320
   at Sparrow.Json.JsonOperationContext.ReadObjectInternal(Object builder, String documentId, UsageMode mode, IBlittableDocumentModifier modifier) in C:\Builds\RavenDB-Stable-4.1\src\Sparrow\Json\JsonOperationContext.cs:line 619
   at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.StoreEntityInUnitOfWork(String id, Object entity, String changeVector, DynamicJsonValue metadata, ConcurrencyCheckMode forceConcurrencyCheck) in C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs:line 741
   at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.StoreInternal(Object entity, String changeVector, String id, ConcurrencyCheckMode forceConcurrencyCheck) in C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs:line 673
   at Raven.Client.Documents.Session.InMemoryDocumentSessionOperations.StoreAsyncInternal(Object entity, String changeVector, String id, ConcurrencyCheckMode forceConcurrencyCheck, CancellationToken token) in C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs:line 703
   <Project Specific StackTrace>
   at lambda_method(Closure , Object )
   at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()

有趣的是,该应用程序在具有相同设置和相同框架集的一台非常相似的计算机中可以完美运行。我不确定是什么导致此Raven失败。任何指针都将受到高度赞赏。

2 个答案:

答案 0 :(得分:1)

类似 System.Runtime.CompilerServices.Unsafe 的安装不正确。

尝试:

 1.安装和使用最新的RavenDB客户端软件包 -OR-

 2.尝试从以下位置手动安装      https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe/

Install-Package System.Runtime.CompilerServices.Unsafe -Version 4.5.2

答案 1 :(得分:0)

摆弄了一天多之后。通过以下设置,我可以在本地计算机上重现该问题:

  • 未安装DOTNET Core SDK

  • .NET Core 2.1.3.NET Core 2.2.0

  • 安装了.NET Core托管和运行时。

enter image description here

如果我还在计算机上安装了.NET Core 2.1.6托管和运行时(带有或不带有2.1.3),问题就消失了。

这使我相信,在受影响的环境上进行的.NET Core 2.1.6安装已损坏。因此,我卸载并重新安装了.NET Core 2.1.6 Hosting and Runtime,并解决了这个不可思议的问题。

但是,这现在使我们的IT变得有些紧张和紧张,因为他们现在感觉托管和运行时不再受信任。实际上,您在遇到此类问题时处于黑暗中。