Skip to content

Commit df8c383

Browse files
committed
Make property set logic robust to irregular properties
1 parent 04d694d commit df8c383

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,14 @@ bool TryCallCtor(Type type, Dictionary<string, IConfigurationSection> suppliedAr
185185
}
186186
else
187187
{
188-
return new { ci, args, isCallable = false, matches, stringMatches, suppliedNames };
188+
return new { ci, args, isCallable = false, matches, stringMatches,
189+
usedArguments = suppliedNames };
189190
}
190191
}
191192
}
192193

193-
return new { ci, args, isCallable = true, matches, stringMatches, suppliedNames };
194+
return new { ci, args, isCallable = true, matches, stringMatches,
195+
usedArguments = suppliedNames };
194196
})
195197
.Where(binding => binding.isCallable)
196198
.OrderByDescending(binding => binding.matches)
@@ -217,7 +219,11 @@ bool TryCallCtor(Type type, Dictionary<string, IConfigurationSection> suppliedAr
217219

218220
foreach (var pi in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
219221
{
220-
if (!binding.suppliedNames.Contains(pi.Name) && suppliedArguments.TryGetValue(pi.Name, out var section) && pi.CanWrite)
222+
if (!binding.usedArguments.Contains(pi.Name) &&
223+
suppliedArguments.TryGetValue(pi.Name, out var section)
224+
&& pi.CanWrite &&
225+
// This avoids trying to call esoteric indexers and so on.
226+
pi.GetSetMethod(false)?.GetParameters().Length == 1)
221227
{
222228
var propertyValue = FromSection(section, _configurationAssemblies);
223229
try

0 commit comments

Comments
 (0)