保存到 Raven 时出现异常

Exception while saving to Raven

我在我们的一个环境中尝试将实体保存到 Raven 时遇到异常。

详情如下:

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

RavenDB.Client 版本: 4.1.2

.Net Core Runtime and Hosting Bundle 安装在服务器上

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 失败。非常感谢任何指点。

看起来 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

折腾了一天多。我能够通过以下设置在我的本地机器上重现该问题:

  • 没有安装 DOTNET Core SDK

  • .NET Core 2.1.3.NET Core 2.2.0

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

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

这让我相信 .NET Core 2.1.6 在受影响的环境中安装已损坏。所以我卸载并重新安装了 .NET Core 2.1.6 Hosting and Runtime,并神奇地解决了这个问题。

然而,这现在让我们的 IT 变得有些紧张和不安,因为他们现在觉得托管和运行时不再可信。遇到这样的问题你简直就是在黑暗中拍摄。