Skip to content

Exceptions when misconfigured #155

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 8 commits into from
Jun 2, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ internal static MethodInfo SelectConfigurationMethod(IEnumerable<MethodInfo> can
// Per issue #111, it is safe to use case-insensitive matching on argument names. The CLR doesn't permit this type
// of overloading, and the Microsoft.Extensions.Configuration keys are case-insensitive (case is preserved with some
// config sources, but key-matching is case-insensitive and case-preservation does not appear to be guaranteed).
return candidateMethods
var selectedMethod = candidateMethods
.Where(m => m.Name == name)
.Where(m => m.GetParameters()
.Skip(1)
Expand All @@ -357,6 +357,27 @@ internal static MethodInfo SelectConfigurationMethod(IEnumerable<MethodInfo> can
matchingArgs.Count(p => p.ParameterType == typeof(string)));
})
.FirstOrDefault();

if (selectedMethod == null)
{
var methodsByName = candidateMethods
.Where(m => m.Name == name)
.Select(m => $"{m.Name}({string.Join(", ", m.GetParameters().Skip(1).Select(p => p.Name))})")
.ToList();

if (!methodsByName.Any())
SelfLog.WriteLine($"Unable to find a method called {name}. Candidate methods are:{Environment.NewLine}{string.Join(Environment.NewLine, candidateMethods)}");
else
SelfLog.WriteLine($"Unable to find a method called {name} "
+ (suppliedArgumentNames.Any()
? "for supplied arguments: " + string.Join(", ", suppliedArgumentNames)
: "with no supplied arguments")
+ ". Candidate methods are:"
+ Environment.NewLine
+ string.Join(Environment.NewLine, methodsByName));
}

return selectedMethod;
}

static bool ParameterNameMatches(string actualParameterName, string suppliedName)
Expand Down