Skip to content

Commit eb76760

Browse files
authored
fix null reference in PSApplicationInsightsComponent (#20709)
1 parent c452ba4 commit eb76760

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

src/ApplicationInsights/custom/Models/PSApplicationInsightsComponent.cs

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ public class PSApplicationInsightsComponent
2424
{
2525
public PSApplicationInsightsComponent(ApplicationInsightsComponent component)
2626
{
27-
this.ResourceGroupName = ParseResourceGroupFromId(component.Id);
28-
this.Name = component.Name;
29-
this.Id = component.Id;
30-
this.Location = component.Location;
31-
this.Tags = component.Tag.Keys.ToDictionary(x => x, x => component.Tag[x]);
32-
this.Kind = component.Kind;
33-
this.Type = component.Type;
34-
this.AppId = component.AppId;
35-
this.ApplicationId = component.ApplicationId;
36-
this.ApplicationType = component.ApplicationType;
37-
this.CreationDate = component.CreationDate;
38-
this.FlowType = component.FlowType;
39-
this.HockeyAppId = component.HockeyAppId;
40-
this.HockeyAppToken = component.HockeyAppToken;
41-
this.InstrumentationKey = component.InstrumentationKey;
42-
this.ProvisioningState = component.ProvisioningState;
43-
this.RequestSource = component.RequestSource;
44-
this.SamplingPercentage = component.SamplingPercentage;
45-
this.TenantId = component.TenantId;
46-
this.PublicNetworkAccessForIngestion = component.PublicNetworkAccessForIngestion;
47-
this.PublicNetworkAccessForQuery = component.PublicNetworkAccessForQuery;
48-
this.PrivateLinkScopedResources = component.PrivateLinkScopedResource.ToList();
49-
this.RetentionInDays = component.RetentionInDay;
50-
this.ConnectionString = component.ConnectionString;
27+
this.ResourceGroupName = ParseResourceGroupFromId(component?.Id);
28+
this.Name = component?.Name;
29+
this.Id = component?.Id;
30+
this.Location = component?.Location;
31+
this.Tags = component?.Tag?.Keys?.ToDictionary(x => x, x => component.Tag[x]);
32+
this.Kind = component?.Kind;
33+
this.Type = component?.Type;
34+
this.AppId = component?.AppId;
35+
this.ApplicationId = component?.ApplicationId;
36+
this.ApplicationType = component?.ApplicationType;
37+
this.CreationDate = component?.CreationDate;
38+
this.FlowType = component?.FlowType;
39+
this.HockeyAppId = component?.HockeyAppId;
40+
this.HockeyAppToken = component?.HockeyAppToken;
41+
this.InstrumentationKey = component?.InstrumentationKey;
42+
this.ProvisioningState = component?.ProvisioningState;
43+
this.RequestSource = component?.RequestSource;
44+
this.SamplingPercentage = component?.SamplingPercentage;
45+
this.TenantId = component?.TenantId;
46+
this.PublicNetworkAccessForIngestion = component?.PublicNetworkAccessForIngestion;
47+
this.PublicNetworkAccessForQuery = component?.PublicNetworkAccessForQuery;
48+
this.PrivateLinkScopedResources = component?.PrivateLinkScopedResource?.ToList();
49+
this.RetentionInDays = component?.RetentionInDay;
50+
this.ConnectionString = component?.ConnectionString;
5151
}
5252

5353
public string Id { get; set; }
@@ -145,7 +145,7 @@ public PSApplicationInsightsComponentWithPricingPlan(ApplicationInsightsComponen
145145
ApplicationInsightsComponentQuotaStatus status)
146146
: base(component)
147147
{
148-
if (billing.CurrentBillingFeature.Any(f => f.Contains("Enterprise")))
148+
if (billing != null && billing.CurrentBillingFeature != null && billing.CurrentBillingFeature.Any(f => f.Contains("Enterprise")))
149149
{
150150
this.PricingPlan = "Application Insights Enterprise";
151151
}
@@ -154,11 +154,13 @@ public PSApplicationInsightsComponentWithPricingPlan(ApplicationInsightsComponen
154154
this.PricingPlan = billing.CurrentBillingFeature.FirstOrDefault();
155155
}
156156

157-
this.Cap = billing.DataVolumeCap.Cap;
158-
this.ResetTime = billing.DataVolumeCap.ResetTime;
159-
this.StopSendNotificationWhenHitCap = billing.DataVolumeCap.StopSendNotificationWhenHitCap.Value;
160-
this.CapExpirationTime = status.ExpirationTime;
161-
this.IsCapped = status.ShouldBeThrottled != null ? status.ShouldBeThrottled.Value : false;
157+
this.Cap = billing?.DataVolumeCap?.Cap;
158+
this.ResetTime = billing?.DataVolumeCap?.ResetTime;
159+
if (billing != null && billing.DataVolumeCap != null && billing.DataVolumeCap.StopSendNotificationWhenHitCap != null) {
160+
this.StopSendNotificationWhenHitCap = billing.DataVolumeCap.StopSendNotificationWhenHitCap.Value;
161+
}
162+
this.CapExpirationTime = status?.ExpirationTime;
163+
this.IsCapped = status?.ShouldBeThrottled != null ? status.ShouldBeThrottled.Value : false;
162164
}
163165
}
164166
}

0 commit comments

Comments
 (0)