【问题标题】:Azure Search .Net SDK throws InvalidOperationException with SerializationBinderAzure Search .Net SDK 使用 SerializationBinder 引发 InvalidOperationException
【发布时间】:2018-02-14 03:52:48
【问题描述】:

我正在 .NET Core 上使用 Azure Search .NET SDK(具体来说,从 Github 克隆示例 - https://github.com/Azure-Samples/search-dotnet-getting-started

当输入任何带有索引的操作(创建、删除...)时,它会抛出来自 Newtonsoft.Json 的 SerializationBinder 异常,如下所示

System.InvalidOperationException: Cannot get SerializationBinder because an ISerializationBinder was previously set.    at Newtonsoft.Json.JsonSerializer.get_Binder()    
--- End of inner exception stack trace ---    
    at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)    
    at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)    
    at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)   
    at Microsoft.Rest.Azure.JsonSerializerExtensions.WithoutConverter(JsonSerializer serializer, JsonConverter converterToExclude)    
    at Microsoft.Rest.Azure.CloudErrorJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)    
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)   
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)    
    at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)    
    at Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject[T](String json, JsonSerializerSettings settings)    at Microsoft.Azure.Search.IndexesOperations.<GetWithHttpMessagesAsync>d__12.MoveNext()
    --- 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 Microsoft.Azure.Search.ExistsHelper.<ExistsFromGetResponse>d__0`1.MoveNext()
--- 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 Microsoft.Azure.Search.IndexesOperationsExtensions.<ExistsAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown --

我认为这是 SDK 本身的问题,因为我克隆了公共 github 存储库。对吗?

【问题讨论】:

    标签: azure azure-cognitive-search azure-sdk-.net azure-search-.net-sdk


    【解决方案1】:

    这是由许多 Azure SDK 与 JSON.NET 版本 10 的已知兼容性问题引起的。详细信息为 herehere

    这已在 Microsoft.Azure.Search 版本 3.0.5 和 4.0.2-preview 中得到修复。

    【讨论】:

    • 是我打开的。也是针对这个问题的。
    • 我知道,谢谢。我想在这里捕获详细信息,以帮助遇到此问题的其他人。
    • Bruce - 我刚刚升级到 3.0.5,但仍然出现错误。
    • @IsaacAbraham 看起来像 JSON.NET 11 beta 的兼容性问题。请在 GitHub 上查看我的 cmets。
    【解决方案2】:

    当我尝试执行DeleteHotelsIndexIfExists函数如果索引不存在时,我也可以重现您提到的问题。 创建索引上传文档等其他操作在我这边工作正常。

    经过一番调查,我发现 Microsoft.Extensions.Configuration.Json 是预览版。

    请尝试更新到最新的稳定 1.1.2 版本。然后它在我这边正常工作。

    【讨论】:

    • 你是对的,它会因 Exists 函数而崩溃。但是,更新 Microsoft.Extensions.Configuration.Json 不起作用(在我的工作项目的情况下从 2.0.0-pre 降级)
    • 如果有用,请点赞,帮助更多有相同问题的社区。​​span>
    • 你说得对,我们需要降级 Microsoft.Extensions.Configuration.Json,我还提到使用最新的 stable 1.1.2 版本。
    • 我可以确认您的解决方案适用于示例存储库,但我相信这不是异常的真正原因。我打开了an issue,团队已经给出了解决方法。希望他们尽快完成。
    猜你喜欢
    • 2018-09-14
    • 1970-01-01
    • 2020-06-25
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多