0

I'm playing around with Azure Search .NET SDK on .NET Core (specifically, cloning the sample from Github - https://github.com/Azure-Samples/search-dotnet-getting-started)

When entering any operation with index (create, delete...) it throws an exception with SerializationBinder from Newtonsoft.Json like this

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 --

I believe that's something wrong with the SDK itself as I cloned the public github repo. Is that right?

Nhan Nguyen
  • 106
  • 1
  • 8

2 Answers2

1

This was caused by a known compatibility issue that many Azure SDKs have with JSON.NET version 10. The details are here and here.

This was fixed in Microsoft.Azure.Search versions 3.0.5 and 4.0.2-preview.

Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42
0

I also can repro the issue you mentioned when I try to execute DeleteHotelsIndexIfExists function if the index is not existed. Other actions such as Creating index,Uploading documents there are working correctly on my side.

After some investigation, I found that Microsoft.Extensions.Configuration.Json is preview version.

Please have a try to update to lastest stable 1.1.2 version. Then it works correctly on my side.

enter image description here

enter image description here

Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47
  • You are correct, it crashes with **Exists** functions. However, updating **Microsoft.Extensions.Configuration.Json** does not work (literally downgrading from 2.0.0-pre, in case of my working project) – Nhan Nguyen Jul 03 '17 at 22:08
  • If it is useful, please mark it that will help more communities who have the same issue. – Tom Sun - MSFT Jul 03 '17 at 23:04
  • You are right, we need to downgrade **Microsoft.Extensions.Configuration.Json**, I also mentioned that use lastest **stable 1.1.2** version. – Tom Sun - MSFT Jul 03 '17 at 23:19
  • I can confirm that your solution works with the sample repo but I believe it is not the real cause of the exception. I opened [an issue](https://github.com/Azure/azure-sdk-for-net/issues/3441) and the team has already given a workaround. Hope they get it done soon. – Nhan Nguyen Jul 04 '17 at 04:41