Skip to content

fix the NullReferenceException issue in Azure.ResourceManager.Network #50935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions sdk/network/Azure.ResourceManager.Network/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Release History

## 1.12.0-beta.1 (Unreleased)

### Features Added

### Breaking Changes
## 1.11.1 (2025-07-01)

### Bugs Fixed

### Other Changes
- 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)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.12.0-beta.1</Version>
<Version>1.11.1</Version>
<!--The ApiCompatVersion is managed automatically and should not generally be modified manually.-->
<ApiCompatVersion>1.11.0</ApiCompatVersion>
<PackageId>Azure.ResourceManager.Network</PackageId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Azure.Core;
using Azure.ResourceManager.Network.Models;
using Azure.ResourceManager.Resources.Models;
Expand All @@ -14,17 +14,20 @@ namespace Azure.ResourceManager.Network
{
public partial class LoadBalancingRuleData : NetworkResourceData
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void EnsureProperties()
{
Properties ??= new LoadBalancingRuleProperties(default, default);
}

/// <summary> Gets or sets Id. </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public ResourceIdentifier FrontendIPConfigurationId
{
get => Properties?.FrontendIPConfigurationId;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.FrontendIPConfigurationId = value;
}
}
Expand All @@ -36,17 +39,21 @@ public ResourceIdentifier BackendAddressPoolId
get => Properties?.BackendAddressPoolId;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.BackendAddressPoolId = value;
}
}

/// <summary> An array of references to pool of DIPs. </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public IList<WritableSubResource> BackendAddressPools => Properties?.BackendAddressPools;
public IList<WritableSubResource> BackendAddressPools
{
get
{
EnsureProperties();
return Properties.BackendAddressPools;
}
}

/// <summary> Gets or sets Id. </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
Expand All @@ -55,10 +62,7 @@ public ResourceIdentifier ProbeId
get => Properties?.ProbeId;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.ProbeId = value;
}
}
Expand All @@ -70,10 +74,7 @@ public LoadBalancingTransportProtocol? Protocol
get => Properties?.Protocol;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.Protocol = value ?? default;
}
}
Expand All @@ -85,10 +86,7 @@ public LoadDistribution? LoadDistribution
get => Properties?.LoadDistribution;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.LoadDistribution = value;
}
}
Expand All @@ -100,10 +98,7 @@ public int? FrontendPort
get => Properties?.FrontendPort;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.FrontendPort = value ?? default;
}
}
Expand All @@ -115,10 +110,7 @@ public int? BackendPort
get => Properties?.BackendPort;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.BackendPort = value;
}
}
Expand All @@ -130,10 +122,7 @@ public int? IdleTimeoutInMinutes
get => Properties?.IdleTimeoutInMinutes;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.IdleTimeoutInMinutes = value;
}
}
Expand All @@ -145,10 +134,7 @@ public bool? EnableFloatingIP
get => Properties?.EnableFloatingIP;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.EnableFloatingIP = value;
}
}
Expand All @@ -160,10 +146,7 @@ public bool? EnableTcpReset
get => Properties?.EnableTcpReset;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.EnableTcpReset = value;
}
}
Expand All @@ -175,10 +158,7 @@ public bool? DisableOutboundSnat
get => Properties?.DisableOutboundSnat;
set
{
if (Properties is null)
{
Properties = new LoadBalancingRuleProperties();
}
EnsureProperties();
Properties.DisableOutboundSnat = value;
}
}
Expand Down