From 32efed504113a4e8098172c8f8b5264caf5f58f1 Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Fri, 27 Jun 2025 17:05:09 +0800 Subject: [PATCH 1/4] fix the nullreferenceexception issue --- .../CHANGELOG.md | 8 ++----- .../src/Azure.ResourceManager.Network.csproj | 2 +- .../Customization/LoadBalancingRuleData.cs | 22 +++++++++---------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md b/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md index 5a7af8e0c99a..f7e26781fd8c 100644 --- a/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md +++ b/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md @@ -1,14 +1,10 @@ # Release History -## 1.12.0-beta.1 (Unreleased) - -### Features Added - -### Breaking Changes +## 1.11.1 (2025-06-27) ### Bugs Fixed -### Other Changes +- Fixed a issue that if `LoadBalancingRuleData.FrontendIPConfigurationId` or other hidden properties on `LoadBalancingRuleData` class are assigned with values, the corresponding service operation would fail with `NullReferenceException` because the collection properties on `LoadBalancingRuleData` class are not initialized. ## 1.11.0 (2025-05-22) diff --git a/sdk/network/Azure.ResourceManager.Network/src/Azure.ResourceManager.Network.csproj b/sdk/network/Azure.ResourceManager.Network/src/Azure.ResourceManager.Network.csproj index ca158ce78b99..4a485684c409 100644 --- a/sdk/network/Azure.ResourceManager.Network/src/Azure.ResourceManager.Network.csproj +++ b/sdk/network/Azure.ResourceManager.Network/src/Azure.ResourceManager.Network.csproj @@ -1,6 +1,6 @@ - 1.12.0-beta.1 + 1.11.1 1.11.0 Azure.ResourceManager.Network diff --git a/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs b/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs index ea19aa453ace..6ef0ee4880ef 100644 --- a/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs +++ b/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs @@ -23,7 +23,7 @@ public ResourceIdentifier FrontendIPConfigurationId { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.FrontendIPConfigurationId = value; } @@ -38,7 +38,7 @@ public ResourceIdentifier BackendAddressPoolId { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.BackendAddressPoolId = value; } @@ -57,7 +57,7 @@ public ResourceIdentifier ProbeId { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.ProbeId = value; } @@ -72,7 +72,7 @@ public LoadBalancingTransportProtocol? Protocol { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.Protocol = value ?? default; } @@ -87,7 +87,7 @@ public LoadDistribution? LoadDistribution { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.LoadDistribution = value; } @@ -102,7 +102,7 @@ public int? FrontendPort { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.FrontendPort = value ?? default; } @@ -117,7 +117,7 @@ public int? BackendPort { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.BackendPort = value; } @@ -132,7 +132,7 @@ public int? IdleTimeoutInMinutes { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.IdleTimeoutInMinutes = value; } @@ -147,7 +147,7 @@ public bool? EnableFloatingIP { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.EnableFloatingIP = value; } @@ -162,7 +162,7 @@ public bool? EnableTcpReset { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.EnableTcpReset = value; } @@ -177,7 +177,7 @@ public bool? DisableOutboundSnat { if (Properties is null) { - Properties = new LoadBalancingRuleProperties(); + Properties = new LoadBalancingRuleProperties(default, default); } Properties.DisableOutboundSnat = value; } From 9382f665990da52522b6bbc76d7b7dac53273526 Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Fri, 27 Jun 2025 17:12:19 +0800 Subject: [PATCH 2/4] clean up --- .../src/Customization/LoadBalancingRuleData.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs b/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs index 6ef0ee4880ef..062a68017112 100644 --- a/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs +++ b/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs @@ -3,7 +3,6 @@ #nullable disable -using System; using System.Collections.Generic; using System.ComponentModel; using Azure.Core; From af2952bff9f6ee39276803a9f5249e53ec1a60c0 Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Fri, 27 Jun 2025 21:13:43 +0800 Subject: [PATCH 3/4] resolve comments --- .../CHANGELOG.md | 2 +- .../Customization/LoadBalancingRuleData.cs | 65 ++++++------------- 2 files changed, 22 insertions(+), 45 deletions(-) diff --git a/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md b/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md index f7e26781fd8c..b5f3d4fd632f 100644 --- a/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md +++ b/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md @@ -4,7 +4,7 @@ ### Bugs Fixed -- Fixed a issue that if `LoadBalancingRuleData.FrontendIPConfigurationId` or other hidden properties on `LoadBalancingRuleData` class are assigned with values, the corresponding service operation would fail with `NullReferenceException` because the collection properties on `LoadBalancingRuleData` class are not initialized. +- Fixed an issue that if `LoadBalancingRuleData.FrontendIPConfigurationId` or other hidden properties on `LoadBalancingRuleData` class are assigned with values, the corresponding service operation would fail with `NullReferenceException` because the collection properties on `LoadBalancingRuleData` class are not initialized. ## 1.11.0 (2025-05-22) diff --git a/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs b/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs index 062a68017112..00dc3e878dae 100644 --- a/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs +++ b/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.ComponentModel; +using System.Runtime.CompilerServices; using Azure.Core; using Azure.ResourceManager.Network.Models; using Azure.ResourceManager.Resources.Models; @@ -13,6 +14,15 @@ namespace Azure.ResourceManager.Network { public partial class LoadBalancingRuleData : NetworkResourceData { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private void EnsureProperties() + { + if (Properties is null) + { + Properties = new LoadBalancingRuleProperties(default, default); + } + } + /// Gets or sets Id. [EditorBrowsable(EditorBrowsableState.Never)] public ResourceIdentifier FrontendIPConfigurationId @@ -20,10 +30,7 @@ public ResourceIdentifier FrontendIPConfigurationId get => Properties?.FrontendIPConfigurationId; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.FrontendIPConfigurationId = value; } } @@ -35,10 +42,7 @@ public ResourceIdentifier BackendAddressPoolId get => Properties?.BackendAddressPoolId; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.BackendAddressPoolId = value; } } @@ -54,10 +58,7 @@ public ResourceIdentifier ProbeId get => Properties?.ProbeId; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.ProbeId = value; } } @@ -69,10 +70,7 @@ public LoadBalancingTransportProtocol? Protocol get => Properties?.Protocol; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.Protocol = value ?? default; } } @@ -84,10 +82,7 @@ public LoadDistribution? LoadDistribution get => Properties?.LoadDistribution; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.LoadDistribution = value; } } @@ -99,10 +94,7 @@ public int? FrontendPort get => Properties?.FrontendPort; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.FrontendPort = value ?? default; } } @@ -114,10 +106,7 @@ public int? BackendPort get => Properties?.BackendPort; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.BackendPort = value; } } @@ -129,10 +118,7 @@ public int? IdleTimeoutInMinutes get => Properties?.IdleTimeoutInMinutes; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.IdleTimeoutInMinutes = value; } } @@ -144,10 +130,7 @@ public bool? EnableFloatingIP get => Properties?.EnableFloatingIP; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.EnableFloatingIP = value; } } @@ -159,10 +142,7 @@ public bool? EnableTcpReset get => Properties?.EnableTcpReset; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.EnableTcpReset = value; } } @@ -174,10 +154,7 @@ public bool? DisableOutboundSnat get => Properties?.DisableOutboundSnat; set { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + EnsureProperties(); Properties.DisableOutboundSnat = value; } } From cf9ad5032e67057dc4ef8931277633b9f8b4117c Mon Sep 17 00:00:00 2001 From: Arcturus Zhang Date: Tue, 1 Jul 2025 10:45:55 +0800 Subject: [PATCH 4/4] refine and change release date to today --- .../Azure.ResourceManager.Network/CHANGELOG.md | 2 +- .../src/Customization/LoadBalancingRuleData.cs | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md b/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md index b5f3d4fd632f..78c7eb9b5a8d 100644 --- a/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md +++ b/sdk/network/Azure.ResourceManager.Network/CHANGELOG.md @@ -1,6 +1,6 @@ # Release History -## 1.11.1 (2025-06-27) +## 1.11.1 (2025-07-01) ### Bugs Fixed diff --git a/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs b/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs index 00dc3e878dae..41695ce1fbcb 100644 --- a/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs +++ b/sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs @@ -17,10 +17,7 @@ public partial class LoadBalancingRuleData : NetworkResourceData [MethodImpl(MethodImplOptions.AggressiveInlining)] private void EnsureProperties() { - if (Properties is null) - { - Properties = new LoadBalancingRuleProperties(default, default); - } + Properties ??= new LoadBalancingRuleProperties(default, default); } /// Gets or sets Id. @@ -49,7 +46,14 @@ public ResourceIdentifier BackendAddressPoolId /// An array of references to pool of DIPs. [EditorBrowsable(EditorBrowsableState.Never)] - public IList BackendAddressPools => Properties?.BackendAddressPools; + public IList BackendAddressPools + { + get + { + EnsureProperties(); + return Properties.BackendAddressPools; + } + } /// Gets or sets Id. [EditorBrowsable(EditorBrowsableState.Never)]