Skip to content

Commit ce0cd19

Browse files
committed
Fix: NullException in SNMP OID selection
1 parent 0475c0c commit ce0cd19

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

Source/NETworkManager/ViewModels/DNSLookupSettingsViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ public DNSLookupSettingsViewModel()
334334
return !info.UseWindowsDNSServer;
335335
};
336336

337+
SelectedDNSServer = DNSServers.Cast<DNSServerConnectionInfoProfile>().FirstOrDefault(x => !x.UseWindowsDNSServer);
338+
337339
LoadSettings();
338340

339341
_isLoading = false;
@@ -349,7 +351,7 @@ private void LoadSettings()
349351
CustomDNSSuffix = SettingsManager.Current.DNSLookup_CustomDNSSuffix;
350352
Recursion = SettingsManager.Current.DNSLookup_Recursion;
351353
UseCache = SettingsManager.Current.DNSLookup_UseCache;
352-
QueryClasses = Enum.GetValues(typeof(QueryClass)).Cast<QueryClass>().OrderBy(x => x.ToString()).ToList();
354+
QueryClasses = [.. Enum.GetValues<QueryClass>().Cast<QueryClass>().OrderBy(x => x.ToString())];
353355
QueryClass = QueryClasses.First(x => x == SettingsManager.Current.DNSLookup_QueryClass);
354356
//ShowOnlyMostCommonQueryTypes = SettingsManager.Current.DNSLookup_ShowOnlyMostCommonQueryTypes;
355357
UseTCPOnly = SettingsManager.Current.DNSLookup_UseTCPOnly;

Source/NETworkManager/ViewModels/SNMPOIDProfilesViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel;
3+
using System.Linq;
34
using System.Windows.Data;
45
using System.Windows.Input;
56
using NETworkManager.Models.Network;
@@ -37,6 +38,8 @@ public SNMPOIDProfilesViewModel(Action<SNMPOIDProfilesViewModel> okCommand,
3738
return info.Name.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1 ||
3839
info.OID.IndexOf(search, StringComparison.OrdinalIgnoreCase) > -1;
3940
};
41+
42+
SelectedOIDProfile = OIDProfiles.Cast<SNMPOIDProfileInfo>().FirstOrDefault();
4043
}
4144

4245
public ICommand OKCommand { get; }
@@ -54,6 +57,8 @@ public string Search
5457

5558
OIDProfiles.Refresh();
5659

60+
SelectedOIDProfile = OIDProfiles.Cast<SNMPOIDProfileInfo>().FirstOrDefault();
61+
5762
OnPropertyChanged();
5863
}
5964
}

Source/NETworkManager/ViewModels/SNMPViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,12 @@ private async Task OpenOIDProfileSelection()
655655
{
656656
childWindow.IsOpen = false;
657657
ConfigurationManager.Current.IsChildWindowOpen = false;
658+
659+
if (instance.SelectedOIDProfile == null)
660+
return;
658661

659662
Mode = instance.SelectedOIDProfile.Mode;
660-
Oid = instance.SelectedOIDProfile.OID;
663+
Oid = instance.SelectedOIDProfile?.OID;
661664
}, async _ => {
662665
childWindow.IsOpen = false;
663666
ConfigurationManager.Current.IsChildWindowOpen = false;

Source/NETworkManager/Views/SNMPOIDProfilesChildWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
Binding="{Binding (network:SNMPOIDProfileInfo.Mode)}"
4444
SortMemberPath="Mode"
4545
Width="1*" />
46-
</DataGrid.Columns>
46+
</DataGrid.Columns>
4747
<DataGrid.InputBindings>
4848
<KeyBinding Command="{Binding Path=OKCommand}" Key="Return" />
49-
</DataGrid.InputBindings>
49+
</DataGrid.InputBindings>
5050
<DataGrid.RowStyle>
5151
<Style TargetType="{x:Type TypeName=DataGridRow}"
5252
BasedOn="{StaticResource ResourceKey=MahApps.Styles.DataGridRow}">

0 commit comments

Comments
 (0)