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.

[BUG] Different CultureInfo can cause wrong URL query in AppendQueryDelimited() in RequestUriBuilderExtensions.cs

See original GitHub issue

Library name and version

Azure.Core latest

Describe the bug

Recently, we were reported a bug that our query is malformed in uri.AppendQueryDelimited() function

After digging deeper, it seems our AppendQueryDelimited() in RequestUriBuilderExtensions.cs should also applies value.ToString(TypeFormatters.DefaultNumberFormat, CultureInfo.InvariantCulture) to value otherwise, some culture will incorrectly delimit comma for specific region users.

The original discussion thread: https://learn.microsoft.com/en-us/answers/questions/1193753/azure-maps-routerange-api-invalid-coordinates-or-o?page=1&orderby=Helpful&comment=answer-1193064#newest-answer-comment

An example code snippet looks like below:

using Azure;
using Azure.Maps.Routing;
using Azure.Maps.Routing.Models;
using System.Globalization;
using System.Text.Json;

namespace Program
{
    internal class Program
    {
        static void Main(string[] args)
        {
            // Comment out the line below to repro the correct scenario
            Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
            var credential = new AzureKeyCredential("<Azure Maps Credential>");
            var _routeClient = new MapsRoutingClient(credential);

            var options = new RouteRangeOptions(10.752276, 45.521535)
            {
                TimeBudget = new TimeSpan(0, 100, 0)
            };

            try
            {
                //Using the options and the route client, get route range result and serialize it as JSON.

                Response<RouteRangeResult> result = _routeClient.GetRouteRange(options);
                //Write the result to the console as JSON.
                Console.WriteLine("Route Range Result:");
                Console.WriteLine(JsonSerializer.Serialize(result.Value));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

Note: To make the program runnable, please install Azure.Maps.Routing nuget package:

dotnet add package Azure.Maps.Routing --prerelease

Note 2: Create an Azure Maps account and replace line 15 "<Azure Maps Credential>" to your Azure Maps credential. See the instruction in the C# Developer Guide

Expected behavior

A json that contains some map route result like:

{
  "FormatVersion":"0.0.1",
  "ReachableRange": { ... } 
}

Actual behavior

It will return 400 error code and shows:

{
  "error":
  {
    "code":"400 BadRequest",
    "message":"The provided coordinates in query are invalid, out of range, or not in the expected format"
  }
}

Reproduction Steps

Comment line 15: Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR"); to see the correct behavior. Uncomment line 15 will show error (400 error code)

Environment

dotnet 6.0 (or above) IDE: Visual Studio Code (or Visual Studio)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
dubietycommented, Jul 13, 2023

The bug is fixed in Azure.Maps.Routing v1.0.0-beta.2. Close the issue.

1reaction
annelo-msftcommented, Jun 21, 2023

Hi @dubiety,

This change actually went into the "Microsoft.Azure.AutoRest.CSharp library, and not Azure.Core. The latest version referenced by Packages.Data.props should have the fix, so I believe whenever you release a new version of Azure.Maps.Routing it should pick up the change. Please reach out if you find that for some reason the problem has not been fixed! Once you have confirmed it is resolved, we can close this issue.

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not get url with query string when changing culture
Culture info is not get query string when I change a language from English to German. Startup.cs services.Configure<RequestLocalizationOptions>( ...
Read more >
When invalid querystring paramater detected in a web ...
In general invalid parameters for URLs accessed only through AJAX requests should be handled as potentially attacks. You may: Simply return an  ......
Read more >
Error "Invalid value for query parameter" and failed to send ...
Learn how to send a proper request with array query parameters with APIKit when invalid query parameter error occurs.
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