Azure Search .Net SDK使用SerializationBinder

时间:2017-07-01 10:45:29

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

我正在使用.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 repo。是吗?

2 个答案:

答案 0 :(得分:1)

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

这已在Microsoft.Azure.Search版本3.0.5和4.0.2预览中修复。

答案 1 :(得分:0)

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

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

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

enter image description here

enter image description here