Skip to content

Commit 22006e2

Browse files
fix the NullReferenceException issue in Azure.ResourceManager.Network (#50935)
* fix the nullreferenceexception issue * clean up * resolve comments * refine and change release date to today
1 parent b9f6f87 commit 22006e2

File tree

3 files changed

+29
-53
lines changed

3 files changed

+29
-53
lines changed

sdk/network/Azure.ResourceManager.Network/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.12.0-beta.1 (Unreleased)
4-
5-
### Features Added
6-
7-
### Breaking Changes
3+
## 1.11.1 (2025-07-01)
84

95
### Bugs Fixed
106

11-
### Other Changes
7+
- 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.
128

139
## 1.11.0 (2025-05-22)
1410

sdk/network/Azure.ResourceManager.Network/src/Azure.ResourceManager.Network.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>1.12.0-beta.1</Version>
3+
<Version>1.11.1</Version>
44
<!--The ApiCompatVersion is managed automatically and should not generally be modified manually.-->
55
<ApiCompatVersion>1.11.0</ApiCompatVersion>
66
<PackageId>Azure.ResourceManager.Network</PackageId>

sdk/network/Azure.ResourceManager.Network/src/Customization/LoadBalancingRuleData.cs

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
#nullable disable
55

6-
using System;
76
using System.Collections.Generic;
87
using System.ComponentModel;
8+
using System.Runtime.CompilerServices;
99
using Azure.Core;
1010
using Azure.ResourceManager.Network.Models;
1111
using Azure.ResourceManager.Resources.Models;
@@ -14,17 +14,20 @@ namespace Azure.ResourceManager.Network
1414
{
1515
public partial class LoadBalancingRuleData : NetworkResourceData
1616
{
17+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
18+
private void EnsureProperties()
19+
{
20+
Properties ??= new LoadBalancingRuleProperties(default, default);
21+
}
22+
1723
/// <summary> Gets or sets Id. </summary>
1824
[EditorBrowsable(EditorBrowsableState.Never)]
1925
public ResourceIdentifier FrontendIPConfigurationId
2026
{
2127
get => Properties?.FrontendIPConfigurationId;
2228
set
2329
{
24-
if (Properties is null)
25-
{
26-
Properties = new LoadBalancingRuleProperties();
27-
}
30+
EnsureProperties();
2831
Properties.FrontendIPConfigurationId = value;
2932
}
3033
}
@@ -36,17 +39,21 @@ public ResourceIdentifier BackendAddressPoolId
3639
get => Properties?.BackendAddressPoolId;
3740
set
3841
{
39-
if (Properties is null)
40-
{
41-
Properties = new LoadBalancingRuleProperties();
42-
}
42+
EnsureProperties();
4343
Properties.BackendAddressPoolId = value;
4444
}
4545
}
4646

4747
/// <summary> An array of references to pool of DIPs. </summary>
4848
[EditorBrowsable(EditorBrowsableState.Never)]
49-
public IList<WritableSubResource> BackendAddressPools => Properties?.BackendAddressPools;
49+
public IList<WritableSubResource> BackendAddressPools
50+
{
51+
get
52+
{
53+
EnsureProperties();
54+
return Properties.BackendAddressPools;
55+
}
56+
}
5057

5158
/// <summary> Gets or sets Id. </summary>
5259
[EditorBrowsable(EditorBrowsableState.Never)]
@@ -55,10 +62,7 @@ public ResourceIdentifier ProbeId
5562
get => Properties?.ProbeId;
5663
set
5764
{
58-
if (Properties is null)
59-
{
60-
Properties = new LoadBalancingRuleProperties();
61-
}
65+
EnsureProperties();
6266
Properties.ProbeId = value;
6367
}
6468
}
@@ -70,10 +74,7 @@ public LoadBalancingTransportProtocol? Protocol
7074
get => Properties?.Protocol;
7175
set
7276
{
73-
if (Properties is null)
74-
{
75-
Properties = new LoadBalancingRuleProperties();
76-
}
77+
EnsureProperties();
7778
Properties.Protocol = value ?? default;
7879
}
7980
}
@@ -85,10 +86,7 @@ public LoadDistribution? LoadDistribution
8586
get => Properties?.LoadDistribution;
8687
set
8788
{
88-
if (Properties is null)
89-
{
90-
Properties = new LoadBalancingRuleProperties();
91-
}
89+
EnsureProperties();
9290
Properties.LoadDistribution = value;
9391
}
9492
}
@@ -100,10 +98,7 @@ public int? FrontendPort
10098
get => Properties?.FrontendPort;
10199
set
102100
{
103-
if (Properties is null)
104-
{
105-
Properties = new LoadBalancingRuleProperties();
106-
}
101+
EnsureProperties();
107102
Properties.FrontendPort = value ?? default;
108103
}
109104
}
@@ -115,10 +110,7 @@ public int? BackendPort
115110
get => Properties?.BackendPort;
116111
set
117112
{
118-
if (Properties is null)
119-
{
120-
Properties = new LoadBalancingRuleProperties();
121-
}
113+
EnsureProperties();
122114
Properties.BackendPort = value;
123115
}
124116
}
@@ -130,10 +122,7 @@ public int? IdleTimeoutInMinutes
130122
get => Properties?.IdleTimeoutInMinutes;
131123
set
132124
{
133-
if (Properties is null)
134-
{
135-
Properties = new LoadBalancingRuleProperties();
136-
}
125+
EnsureProperties();
137126
Properties.IdleTimeoutInMinutes = value;
138127
}
139128
}
@@ -145,10 +134,7 @@ public bool? EnableFloatingIP
145134
get => Properties?.EnableFloatingIP;
146135
set
147136
{
148-
if (Properties is null)
149-
{
150-
Properties = new LoadBalancingRuleProperties();
151-
}
137+
EnsureProperties();
152138
Properties.EnableFloatingIP = value;
153139
}
154140
}
@@ -160,10 +146,7 @@ public bool? EnableTcpReset
160146
get => Properties?.EnableTcpReset;
161147
set
162148
{
163-
if (Properties is null)
164-
{
165-
Properties = new LoadBalancingRuleProperties();
166-
}
149+
EnsureProperties();
167150
Properties.EnableTcpReset = value;
168151
}
169152
}
@@ -175,10 +158,7 @@ public bool? DisableOutboundSnat
175158
get => Properties?.DisableOutboundSnat;
176159
set
177160
{
178-
if (Properties is null)
179-
{
180-
Properties = new LoadBalancingRuleProperties();
181-
}
161+
EnsureProperties();
182162
Properties.DisableOutboundSnat = value;
183163
}
184164
}

0 commit comments

Comments
 (0)