Azure / azure-cosmos-table-dotnet

.NET SDK for Azure Cosmos Table API
14 stars 6 forks source link

Batch operations using custom JsonConvert.DefaultSettings fails #69

Open johanclasson opened 3 years ago

johanclasson commented 3 years ago

SDK version

Microsoft.Azure.Cosmos.Table 1.0.8

I believe that the issue is not present in Microsoft.Azure.Cosmos.Table 2.0.0-preview.

Issue reproduce steps

const string connectionString = "DefaultEndpointsProtocol=https;AccountName=...;AccountKey=...;TableEndpoint=https://....table.cosmos.azure.com:443/;";
const string tableName = "...";

var settings = new JsonSerializerSettings();
settings.Converters.Add(new StringEnumConverter());
JsonConvert.DefaultSettings = () => settings;

var table = CloudStorageAccount.Parse(connectionString)
    .CreateCloudTableClient()
    .GetTableReference(tableName);
var batch = new TableBatchOperation();
batch.InsertOrReplace(new TableEntity("foo", "bar"));
await table.ExecuteBatchAsync(batch);

ExecuteBatchAsync-method fails when connectionString is for CosmosDB Table API.

If the connectionString is changed targeting Table Storage the code works.

Commenting out the line settings.Converters.Add(new StringEnumConverter()); makes the code work.

Using the settings below, that is without any converters added, also makes the code fail.

var settings = new JsonSerializerSettings
{
    TypeNameHandling = TypeNameHandling.Auto
};

Whether the issue is consistent or sporadic

Consistent

Environment Summary

Windows netcoreapp3.1

Any other context, such as stack trace or log.

Microsoft.Azure.Cosmos.Table.StorageException: Error reading JArray from JsonReader. Path '', line 0, position 0.
 ---> Newtonsoft.Json.JsonReaderException: Error reading JArray from JsonReader. Path '', line 0, position 0.
   at Newtonsoft.Json.Linq.JArray.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JArray.Parse(String json, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JArray.Parse(String json)
   at Microsoft.Azure.Cosmos.Table.Extensions.TableExtensionOperationHelper.ExecuteBatchOperationAsync[TResult](TableBatchOperation batch, CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Microsoft.Azure.Cosmos.Table.Extensions.TableExtensionOperationHelper.ExecuteBatchOperationAsync[TResult](TableBatchOperation batch, CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext, CancellationToken cancellationToken)
   at Microsoft.Azure.Cosmos.Table.Extensions.TableExtensionRetryPolicy.ExecuteUnderRetryPolicy[TResult](Func`1 executionMethod, CancellationToken cancellationToken, OperationContext operationContext, TableRequestOptions requestOptions)
   at Test.Program.Main(String[] args) in C:\...\Program.cs:line 38
   at Test.Program.<Main>(String[] args)
Request Information
RequestID:
RequestCharge:0
RequestDate:
StatusMessage:Error reading JArray from JsonReader. Path '', line 0, position 0.
ErrorCode:
ErrorMessage:Error reading JArray from JsonReader. Path '', line 0, position 0.