Skip to content

Commit df627c4

Browse files
fix the culture info issue in LocationMetadata (Azure#49560)
1 parent e5be479 commit df627c4

File tree

5 files changed

+67
-18
lines changed

5 files changed

+67
-18
lines changed

sdk/resourcemanager/Azure.ResourceManager/CHANGELOG.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
# Release History
22

3-
## 1.14.0-beta.1 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
3+
## 1.13.1 (2025-04-24)
84

95
### Bugs Fixed
106

11-
### Other Changes
7+
- Fixed the `Longitude` and `Latitude` in `LocationMetadata` class to use invariant culture during serialization and deserialization. (https://github.com/Azure/azure-sdk-for-net/issues/43116)
128

139
## 1.13.0 (2024-09-03)
1410

sdk/resourcemanager/Azure.ResourceManager/docs/MigrationGuide.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ As you can see, now authentication is handled by Azure.Identity, and just a sing
6868

6969
**Old**
7070
```C#
71-
ServiceClientCredentials credentials = getMyCredentials();
71+
ServiceClientCredentials credentials = getMyCredentials();
7272
ResourceManagementClient resourcesClient = new ResourceManagementClient(credentials);
7373

7474
string rgName = "QuickStartRG";
@@ -112,7 +112,7 @@ AvailabilitySet inputAvailabilitySet = new AvailabilitySet
112112
PlatformUpdateDomainCount = 1,
113113
Sku = new CM.Sku
114114
{
115-
Name = AvailabilitySetSkuTypes.Aligned
115+
Name = AvailabilitySetSkuTypes.Aligned
116116
}
117117
};
118118
string aSetName = "quickstartvm_aSet";
@@ -130,7 +130,7 @@ ArmOperation<AvailabilitySetResource> availabilitySetOperation = await availabil
130130
AvailabilitySetResource availabilitySet = availabilitySetOperation.Value;
131131
```
132132

133-
Parameters can be specified via the `AvailabilitySetData` object, in here, the basic default only requires the location. The availability set is created using the AvailabilitySetsCollection returned from the `GetAvailabilitySets()` extension method instead of using another client.
133+
Parameters can be specified via the `AvailabilitySetData` object, in here, the basic default only requires the location. The availability set is created using the AvailabilitySetsCollection returned from the `GetAvailabilitySets()` extension method instead of using another client.
134134

135135
### Create a Security Group
136136

@@ -256,7 +256,7 @@ ArmOperation<NetworkInterfaceResource> networkInterfaceOperation = await network
256256
NetworkInterfaceResource networkInterface = networkInterfaceOperation.Value;
257257
```
258258

259-
This step is similar to the old SDK, however, notice that the `CreateOrUpdateAsync()` method returns the network interface that has been created.
259+
This step is similar to the old SDK, however, notice that the `CreateOrUpdateAsync()` method returns the network interface that has been created.
260260

261261
### Create a Virtual Machine
262262

@@ -510,7 +510,7 @@ In both libraries, subnets are defined inside virtual networks, however, with th
510510

511511
**Old**
512512
```C#
513-
var virutalMachine = azure.VirtualMachines.Define(virtualMachineName)
513+
var virtualMachine = azure.VirtualMachines.Define(virtualMachineName)
514514
.WithRegion(Region.USEast)
515515
.WithExistingResourceGroup(ResourceGroupName)
516516
.WithExistingPrimaryNetwork(virtualNetwork)

sdk/resourcemanager/Azure.ResourceManager/src/Azure.ResourceManager.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>1.14.0-beta.1</Version>
4+
<Version>1.13.1</Version>
55
<!--The ApiCompatVersion is managed automatically and should not generally be modified manually.-->
66
<ApiCompatVersion>1.13.0</ApiCompatVersion>
77
<PackageId>Azure.ResourceManager</PackageId>

sdk/resourcemanager/Azure.ResourceManager/src/Resources/Custom/Models/LocationMetadata.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#nullable disable
55

66
using System.ClientModel.Primitives;
7+
using System.Globalization;
78
using System.Runtime.CompilerServices;
89
using System.Text.Json;
910
using Azure.Core;
@@ -22,8 +23,14 @@ public partial class LocationMetadata
2223
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2324
internal void WriteLongitude(Utf8JsonWriter writer, ModelReaderWriterOptions options)
2425
{
25-
if (Longitude != null)
26-
writer.WriteStringValue(Longitude.ToString());
26+
if (Longitude.HasValue)
27+
{
28+
writer.WriteStringValue(Longitude.Value.ToString(CultureInfo.InvariantCulture));
29+
}
30+
else
31+
{
32+
writer.WriteNullValue();
33+
}
2734
}
2835

2936
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -32,14 +39,20 @@ internal static void ReadLongitude(JsonProperty property, ref double? longitude)
3239
if (property.Value.ValueKind == JsonValueKind.Null)
3340
return;
3441

35-
longitude = double.Parse(property.Value.GetString());
42+
longitude = double.Parse(property.Value.GetString(), CultureInfo.InvariantCulture);
3643
}
3744

3845
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3946
internal void WriteLatitude(Utf8JsonWriter writer, ModelReaderWriterOptions options)
4047
{
41-
if (Latitude != null)
42-
writer.WriteStringValue(Latitude.ToString());
48+
if (Latitude.HasValue)
49+
{
50+
writer.WriteStringValue(Latitude.Value.ToString(CultureInfo.InvariantCulture));
51+
}
52+
else
53+
{
54+
writer.WriteNullValue();
55+
}
4356
}
4457

4558
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -48,7 +61,7 @@ internal static void ReadLatitude(JsonProperty property, ref double? latitude)
4861
if (property.Value.ValueKind == JsonValueKind.Null)
4962
return;
5063

51-
latitude = double.Parse(property.Value.GetString());
64+
latitude = double.Parse(property.Value.GetString(), CultureInfo.InvariantCulture);
5265
}
5366
}
5467
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.ClientModel.Primitives;
3+
using System.Globalization;
4+
using System.Threading;
5+
using Azure.ResourceManager.Models;
6+
using Azure.ResourceManager.Resources.Models;
7+
using NUnit.Framework;
8+
9+
namespace Azure.ResourceManager.Tests
10+
{
11+
public class LocationMetadataTests
12+
{
13+
private const double _longitude = -122.1215;
14+
private const double _latitude = 47.6740;
15+
private static readonly string _payload = $@"{{""longitude"":""{_longitude}"",""latitude"":""{_latitude}""}}";
16+
17+
[TestCase("en-US")] // English (United States) - uses a dot as the decimal separator
18+
[TestCase("fr-FR")] // French (France) - uses a comma as the decimal separator
19+
[TestCase("de-DE")] // German (Germany) - uses a comma as the decimal separator
20+
[TestCase("es-ES")] // Spanish (Spain) - uses a comma as the decimal separator
21+
[TestCase("it-IT")] // Italian (Italy) - uses a comma as the decimal separator
22+
[TestCase("ja-JP")] // Japanese (Japan) - uses a dot as the decimal separator
23+
[TestCase("zh-CN")] // Chinese (China) - uses a dot as the decimal separator
24+
[TestCase("ru-RU")] // Russian (Russia) - uses a comma as the decimal separator
25+
[TestCase("pt-BR")] // Portuguese (Brazil) - uses a comma as the decimal separator
26+
[TestCase("ar-SA")] // Arabic (Saudi Arabia) - uses a dot as the decimal separator
27+
public void ValidateLocationMetadataInCulture(string culture)
28+
{
29+
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
30+
31+
var location = ModelReaderWriter.Read<LocationMetadata>(new BinaryData(_payload));
32+
33+
Assert.AreEqual(_longitude, location.Longitude);
34+
Assert.AreEqual(_latitude, location.Latitude);
35+
36+
var json = ModelReaderWriter.Write(location);
37+
Assert.AreEqual(_payload, json.ToString());
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)