Skip to content

Commit 8bea591

Browse files
author
Sergey Komisarchik
authored
Merge pull request #220 from skomis-mm/missingTypeMsg
Show better error message for a missing interface parameter type
2 parents cc45629 + 9309608 commit 8bea591

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,22 @@ public object ConvertTo(Type toType, ResolutionContext resolutionContext)
9393
// maybe it's the assembly-qualified type name of a concrete implementation
9494
// with a default constructor
9595
var type = FindType(argumentValue.Trim());
96-
if (type != null)
96+
if (type == null)
9797
{
98-
var ctor = type.GetTypeInfo().DeclaredConstructors.FirstOrDefault(ci =>
99-
{
100-
var parameters = ci.GetParameters();
101-
return parameters.Length == 0 || parameters.All(pi => pi.HasDefaultValue);
102-
});
98+
throw new InvalidOperationException($"Type {argumentValue} was not found.");
99+
}
103100

104-
if (ctor == null)
105-
throw new InvalidOperationException($"A default constructor was not found on {type.FullName}.");
101+
var ctor = type.GetTypeInfo().DeclaredConstructors.FirstOrDefault(ci =>
102+
{
103+
var parameters = ci.GetParameters();
104+
return parameters.Length == 0 || parameters.All(pi => pi.HasDefaultValue);
105+
});
106106

107-
var call = ctor.GetParameters().Select(pi => pi.DefaultValue).ToArray();
108-
return ctor.Invoke(call);
109-
}
107+
if (ctor == null)
108+
throw new InvalidOperationException($"A default constructor was not found on {type.FullName}.");
109+
110+
var call = ctor.GetParameters().Select(pi => pi.DefaultValue).ToArray();
111+
return ctor.Invoke(call);
110112
}
111113

112114
return Convert.ChangeType(argumentValue, toType);

0 commit comments

Comments
 (0)