question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Format exception when using culture and partitionKey, difference between Windows and Linux

See original GitHub issue

Describe the bug We see different behavior between running queries on Linux versus Windows, when using culture Info and partition key/cross-partition key queries.

To Reproduce

using Microsoft.Azure.Cosmos.Fluent;
using Microsoft.Azure.Cosmos;
using Newtonsoft.Json;

namespace ConsoleApp1;

internal class Program
{
    static void Main(string[] args)
    {
        var client = new CosmosClientBuilder("---url---", "---key---").Build();
        var container = client.GetContainer("--database--", "--container--");

        Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

        // Retrieves data
        var noCultureWithPartitionKey = container.GetItemLinqQueryable<QueryObject>(true, null, new QueryRequestOptions() { PartitionKey = new PartitionKey("bc7df108-4c93-4534-ba32-167d77274511") })
            .Where(c => c.Area > 5.65252);
        Console.WriteLine(noCultureWithPartitionKey.Count());

        // Retrieves data, cross partition
        var noCultureNoPk = container.GetItemLinqQueryable<QueryObject>(true, null, new QueryRequestOptions() { PartitionKey = null })
            .Where(c => c.Area > 5.65252);
        Console.WriteLine(noCultureNoPk.Count());

        // Change the culture
        Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR");

        // Throws error
        try
        {
            var withCultureWithPartitionKey = container.GetItemLinqQueryable<QueryObject>(true, null, new QueryRequestOptions() { PartitionKey = new PartitionKey("bc7df108-4c93-4534-ba32-167d77274511") })
                .Where(c => c.Area > 5.65252);
            Console.WriteLine(withCultureWithPartitionKey.Count());
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        // Same query, cross partition
        var withCultureNoPk = container.GetItemLinqQueryable<QueryObject>(true, null, new QueryRequestOptions() { PartitionKey = null })
            .Where(c => c.Area > 5.65252);
        Console.WriteLine(withCultureNoPk.Count());
    }
}

class QueryObject{

    [JsonProperty("id")]
    public string Id{ get; set; }

    [JsonProperty("partitionKey")]
    public string PartitionKey { get; set; }

    [JsonProperty("area")]
    public double Area{ get; set; }
}

Results on Windows:

10
240193
10
240193

Results on Linux:

10
240193
Input string was not in a correct format.
240193

Expected behavior Same behavior when running on Windows/Linux/Docker, independent on the thread culture.

Actual behavior We are running a docker container with an webapi which uses request localization based on the accept language header. Customers from Norway, France are running into problems, because of the “Input string was not in a correct format.” exception (all our queries are on a specific partition key).

Environment summary SDK Version: 2.32.3 OS Version Windows vs Linux (Ubuntu) vs Official Docker images

Additional context Add any other context about the problem here (for example, complete stack traces or logs).

Issue Analytics

  • State:closed
  • Created 6 months ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
neildshcommented, Apr 10, 2023

This looks like the correct diagnosis. I’ll get this issue assigned. Thanks @mlankamp

1reaction
mlankampcommented, Apr 13, 2023

I can provide a PR (and unit-test also ) if you want

Read more comments on GitHub >

github_iconTop Results From Across the Web

Query fails with different CultureInfo · Issue #542
Describe the bug Query fails when different culture is set on the machine. ... FormatException: Input string was not in a correct format....
Read more >
c# - How to query azure table storage with single quote in ...
I am using Windows Azure Storage 7.0.0 and you can use Linq query so that you don't have to escape single quotes :...
Read more >
System.Globalization.CultureNotFoundException with some
I have the Language/Region setting for Office 365 on the web as "English ... Outlook with GNOME Web browser (Epiphany) on Linux, I...
Read more >
Azure PowerShell release notes
Learn about all of the latest updates to the Azure PowerShell modules.
Read more >
Azure Data Factory - JSON Scripting Reference
This article provides JSON schemas and examples for defining Azure Data Factory entities (pipeline, activity, dataset, and linked service). Note.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found