79784109

Date: 2025-10-06 22:08:28
Score: 1
Natty:
Report link

Adding my answer as the accepted answer did not work for me.

The idea is the same, that Cosmos uses Newtonsoft internally for serialization purposes and if you are using System.Text.Json adding the attribute to change the property name to "id" on serialization will not work.

There is a "UseSystemTextJsonSerializerWithOptions" property in CosmosClientOptions that we can set with an object of type JsonSerializerOptions. Just using this has fixed this error for me.

CosmosClientOptions cosmosClientOptions = new CosmosClientOptions()
{
    UseSystemTextJsonSerializerWithOptions = new JsonSerializerOptions()
    {
        PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
        WriteIndented = true,
        PropertyNameCaseInsensitive = true
    }
};

var cosmosClient = new CosmosClient(connectionString: appSettings.CosmosDbConnectionString, cosmosClientOptions);
Reasons:
  • Blacklisted phrase (1): did not work
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: ifg43