diff --git a/mRemoteV1/Connection/DefaultConnectionInfo.cs b/mRemoteV1/Connection/DefaultConnectionInfo.cs index 156df57a..d7f4194f 100644 --- a/mRemoteV1/Connection/DefaultConnectionInfo.cs +++ b/mRemoteV1/Connection/DefaultConnectionInfo.cs @@ -18,11 +18,17 @@ namespace mRemoteNG.Connection public void LoadFrom(TSource sourceInstance, Func propertyNameMutator = null) { - if (propertyNameMutator == null) propertyNameMutator = (a) => a; + if (propertyNameMutator == null) propertyNameMutator = a => a; var connectionProperties = GetProperties(_excludedProperties); foreach (var property in connectionProperties) { var propertyFromSource = typeof(TSource).GetProperty(propertyNameMutator(property.Name)); + if (propertyFromSource == null) + { + Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, + $"DefaultConInfo-LoadFrom: Could not load {property.Name}", true); + continue; + } var valueFromSource = propertyFromSource.GetValue(sourceInstance, null); var descriptor = TypeDescriptor.GetProperties(Instance)[property.Name]; @@ -36,7 +42,7 @@ namespace mRemoteNG.Connection public void SaveTo(TDestination destinationInstance, Func propertyNameMutator = null) { - if (propertyNameMutator == null) propertyNameMutator = (a) => a; + if (propertyNameMutator == null) propertyNameMutator = a => a; var inheritanceProperties = GetProperties(_excludedProperties); foreach (var property in inheritanceProperties) { @@ -44,6 +50,12 @@ namespace mRemoteNG.Connection { var propertyFromDestination = typeof(TDestination).GetProperty(propertyNameMutator(property.Name)); var localValue = property.GetValue(Instance, null); + if (propertyFromDestination == null) + { + Runtime.MessageCollector?.AddMessage(Messages.MessageClass.ErrorMsg, + $"DefaultConInfo-SaveTo: Could not load {property.Name}", true); + continue; + } var convertedValue = Convert.ChangeType(localValue, propertyFromDestination.PropertyType); propertyFromDestination.SetValue(destinationInstance, convertedValue, null); } diff --git a/mRemoteV1/Connection/DefaultConnectionInheritance.cs b/mRemoteV1/Connection/DefaultConnectionInheritance.cs index 1dc37f64..b55ca863 100644 --- a/mRemoteV1/Connection/DefaultConnectionInheritance.cs +++ b/mRemoteV1/Connection/DefaultConnectionInheritance.cs @@ -1,4 +1,5 @@ using System; +using mRemoteNG.App; namespace mRemoteNG.Connection @@ -17,11 +18,17 @@ namespace mRemoteNG.Connection public void LoadFrom(TSource sourceInstance, Func propertyNameMutator = null) { - if (propertyNameMutator == null) propertyNameMutator = (a) => a; + if (propertyNameMutator == null) propertyNameMutator = a => a; var inheritanceProperties = GetProperties(); foreach (var property in inheritanceProperties) { var propertyFromSettings = typeof(TSource).GetProperty(propertyNameMutator(property.Name)); + if (propertyFromSettings == null) + { + Runtime.MessageCollector.AddMessage(Messages.MessageClass.ErrorMsg, + $"DefaultConInherit-LoadFrom: Could not load {property.Name}", true); + continue; + } var valueFromSettings = propertyFromSettings.GetValue(sourceInstance, null); property.SetValue(Instance, valueFromSettings, null); } @@ -29,12 +36,18 @@ namespace mRemoteNG.Connection public void SaveTo(TDestination destinationInstance, Func propertyNameMutator = null) { - if (propertyNameMutator == null) propertyNameMutator = (a) => a; + if (propertyNameMutator == null) propertyNameMutator = a => a; var inheritanceProperties = GetProperties(); foreach (var property in inheritanceProperties) { var propertyFromSettings = typeof(TDestination).GetProperty(propertyNameMutator(property.Name)); var localValue = property.GetValue(Instance, null); + if (propertyFromSettings == null) + { + Runtime.MessageCollector?.AddMessage(Messages.MessageClass.ErrorMsg, + $"DefaultConInherit-SaveTo: Could not load {property.Name}", true); + continue; + } propertyFromSettings.SetValue(destinationInstance, localValue, null); } }