Fixes #248 - Add CultureInfo.InvariantCulture to string interpolation… (#249)

* Fixes #248 - Add CultureInfo.InvariantCulture to string interpolation for langitude and longitude so the sample works everywhere.

* Update samples/QuickstartWeatherServer/Tools/WeatherTools.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
Dominik Guhr 2025-04-09 15:08:27 +02:00 • committed by GitHub
commit 43266ad268
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,6 +1,7 @@
using ModelContextProtocol;
using ModelContextProtocol.Server;
using System.ComponentModel;
using System.Globalization;
using System.Text.Json;
namespace QuickstartWeatherServer.Tools;
@ -41,7 +42,8 @@ public sealed class WeatherTools
[Description("Latitude of the location.")] double latitude,
[Description("Longitude of the location.")] double longitude)
{
using var jsonDocument = await client.ReadJsonDocumentAsync($"/points/{latitude},{longitude}");
var pointUrl = string.Create(CultureInfo.InvariantCulture, $"/points/{latitude},{longitude}");
using var jsonDocument = await client.ReadJsonDocumentAsync(pointUrl);
var forecastUrl = jsonDocument.RootElement.GetProperty("properties").GetProperty("forecast").GetString()
?? throw new Exception($"No forecast URL provided by {client.BaseAddress}points/{latitude},{longitude}");