[BUG] Different CultureInfo can cause wrong URL query in AppendQueryDelimited() in RequestUriBuilderExtensions.cs
See original GitHub issueLibrary 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:
- Created 5 months ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
The bug is fixed in
Azure.Maps.Routing
v1.0.0-beta.2. Close the issue.Hi @dubiety,
This change actually went into the
"Microsoft.Azure.AutoRest.CSharp
library, and notAzure.Core
. The latest version referenced by Packages.Data.props should have the fix, so I believe whenever you release a new version ofAzure.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!