.net core 保存到Raven时发生异常

.net core 保存到Raven时发生异常,.net-core,ravendb,asp.net-core-2.1,.net Core,Ravendb,Asp.net Core 2.1,在我们的一个环境中,我试图将实体保存到Raven时遇到异常 详情如下: 应用程序目标框架:.NET核心2.1 RavenDB.Client版本:4.1.2 服务器上安装的.Net核心运行时和主机包: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken

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

详情如下:

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

RavenDB.Client版本:4.1.2

服务器上安装的.Net核心运行时和主机包

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()
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()
System.IO.FileLoadException:无法加载文件或程序集'System.Runtime.CompilerServices.Unsafe,Version=4.0.4.1,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'。定位的程序集清单定义与程序集引用不匹配。(来自HRESULT的异常:0x8013100)
文件名:“System.Runtime.CompilerServices.Unsafe,版本=4.0.4.1,区域性=neutral,PublicKeyToken=b03f5f7f11d50a3a”
在Sparrow.Json.UnmanagedWriteBuffer.Write(字节*缓冲区,Int32计数)
在C:\Builds\RavenDB-Stable-4.1\src\Sparrow\Json\BlittableWriter.cs中的Sparrow.Json.BlittableWriter`1.WriteValue(字节*缓冲区,Int32大小,FastList`1转义位置,BlittableJsonToken和令牌,UsageMode,Nullable`1 initialCompressedSize)处
在C:\Builds\RavenDB-Stable-4.1\src\Sparrow\Json\blitablejsondocumentbuilder.ReadInternal[twritestracture]()中的Sparrow.Json.blitablejsondocumentbuilder.cs:第320行
在C:\Builds\RavenDB-Stable-4.1\src\Sparrow\Json\Json\JsonOperationContext.ReadObjectInternal(对象生成器、字符串documentId、UsageMode模式、IBlittableDocumentModifier修饰符)中
在C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.cs:第741行中的Raven.Client.Documents.Session.Session.InMemoryDocumentSessionOperations.StoreEntityInUnitOfWork(字符串id、对象实体、字符串更改向量、动态CSONValue元数据、并发检查代码forceconcurrency检查)中
在C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.StoreInternal(对象实体、字符串更改向量、字符串id、并发检查代码forceconcurrency检查)中
在C:\Builds\RavenDB-Stable-4.1\src\Raven.Client\Documents\Session\InMemoryDocumentSessionOperations.StoreAsyncInternal(对象实体、字符串更改向量、字符串id、并发检查代码forceConcurrencyCheck、取消令牌令牌)中
在lambda_方法(闭包,对象)
在Microsoft.Extensions.Internal.ObjectMethodExecutorWaitiable.Waitier.GetResult()中
位于Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper映射器、ObjectMethodExecutor执行器、对象控制器、对象[]参数)
在System.Threading.Tasks.ValueTask`1.get_Result()处
在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()中
在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()上
位于Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext上下文)
位于Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(状态和下一步、范围和范围、对象和状态、布尔值和isCompleted)
在Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()中
在Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()上
有趣的是,该应用程序在一台非常相似的机器上运行得非常好,安装了相同的设置和相同的框架。我不确定是什么导致了这只乌鸦的失败。非常感谢任何指针。

看起来像System.Runtime.CompilerServices.Unsafe没有正确安装

试试看:

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

2.尝试从手动安装


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

  • 未安装DOTNET Core SDK

  • 已为
    .NET Core 2.1.3
    安装.NET Core托管和运行时.NET Core 2.2.0

如果我的机器上也安装了
.netcore2.1.6
托管和运行时(无论是否安装
2.1.3
),那么问题就消失了

这让我相信,在受影响的环境上安装
.NETCore2.1.6
在某种程度上是损坏的。所以我卸载并重新安装了.NETCore2.1.6托管和运行时,神奇地解决了这个问题


然而,这让我们的IT团队感到有些紧张和不安,因为他们现在觉得托管和运行时不再可信。您实际上是在黑暗中拍摄,遇到此类问题。

Hi@danielle,raven dB客户端版本包安装正确。包
System.Runtime.Compiler.Unsafe
是RavenDb的依赖项。我不知道为什么我需要手动安装。我希望它能像预期的那样开箱即用,就像它在一台机器上做的那样,但在另一台机器上却做不到一样。