diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/DllScanningAssemblyFinder.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/DllScanningAssemblyFinder.cs index e571157..38ff3c4 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/DllScanningAssemblyFinder.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/Assemblies/DllScanningAssemblyFinder.cs @@ -32,7 +32,11 @@ public override IReadOnlyList FindAssembliesContainingName(string } else { - probeDirs.Add(Path.GetDirectoryName(typeof(AssemblyFinder).Assembly.Location)); + var assemblyLocation = Path.GetDirectoryName(typeof(AssemblyFinder).Assembly.Location); + if (assemblyLocation != null) + { + probeDirs.Add(assemblyLocation); + } } var query = from probeDir in probeDirs diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs index d5a3a92..d5ed5e3 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ConfigurationReader.cs @@ -484,12 +484,12 @@ static bool HasImplicitValueWhenNotSpecified(ParameterInfo paramInfo) return selectedMethod; } - static bool ParameterNameMatches(string actualParameterName, string suppliedName) + static bool ParameterNameMatches(string? actualParameterName, string suppliedName) { return suppliedName.Equals(actualParameterName, StringComparison.OrdinalIgnoreCase); } - static bool ParameterNameMatches(string actualParameterName, IEnumerable suppliedNames) + static bool ParameterNameMatches(string? actualParameterName, IEnumerable suppliedNames) { return suppliedNames.Any(s => ParameterNameMatches(actualParameterName, s)); } diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/LoggingFilterSwitchProxy.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/LoggingFilterSwitchProxy.cs index a35974e..3b4997d 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/LoggingFilterSwitchProxy.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/LoggingFilterSwitchProxy.cs @@ -15,12 +15,12 @@ class LoggingFilterSwitchProxy _setProxy = (Action)Delegate.CreateDelegate( typeof(Action), realSwitch, - expressionProperty.GetSetMethod()); + expressionProperty.GetSetMethod() ?? throw new MissingMethodException(type.FullName, "set_Expression")); _getProxy = (Func)Delegate.CreateDelegate( typeof(Func), realSwitch, - expressionProperty.GetGetMethod()); + expressionProperty.GetGetMethod() ?? throw new MissingMethodException(type.FullName, "get_Expression")); } public object RealSwitch { get; } @@ -42,6 +42,7 @@ public string? Expression return null; } - return new LoggingFilterSwitchProxy(Activator.CreateInstance(filterSwitchType, expression)); + var realSwitch = Activator.CreateInstance(filterSwitchType, expression) ?? throw new InvalidOperationException($"Activator.CreateInstance returned null for {filterSwitchType}"); + return new LoggingFilterSwitchProxy(realSwitch); } } diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs index 6cc07b4..3a15457 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/ObjectArgumentValue.cs @@ -85,7 +85,7 @@ bool TryCreateContainer([NotNullWhen(true)] out object? result) return false; var configurationElements = _section.GetChildren().ToArray(); - result = Activator.CreateInstance(toType); + result = Activator.CreateInstance(toType) ?? throw new InvalidOperationException($"Activator.CreateInstance returned null for {toType}"); for (int i = 0; i < configurationElements.Length; ++i) { @@ -137,7 +137,7 @@ internal static bool TryBuildCtorExpression( var ctor = (from c in type.GetConstructors() from p in c.GetParameters() - let argumentBindResult = suppliedArguments.TryGetValue(p.Name, out var argValue) switch + let argumentBindResult = suppliedArguments.TryGetValue(p.Name ?? "", out var argValue) switch { true => new { success = true, hasMatch = true, value = (object?)argValue }, false => p.HasDefaultValue switch diff --git a/src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs b/src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs index c26139b..ebf3d2e 100644 --- a/src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs +++ b/src/Serilog.Settings.Configuration/Settings/Configuration/StringArgumentValue.cs @@ -21,7 +21,7 @@ public StringArgumentValue(string providedValue) { { typeof(Uri), s => new Uri(s) }, { typeof(TimeSpan), s => TimeSpan.Parse(s) }, - { typeof(Type), s => Type.GetType(s, throwOnError:true) }, + { typeof(Type), s => Type.GetType(s, throwOnError:true)! }, }; public object? ConvertTo(Type toType, ResolutionContext resolutionContext) @@ -68,7 +68,7 @@ public StringArgumentValue(string providedValue) if (toType != typeof(string) && TryParseStaticMemberAccessor(argumentValue, out var accessorTypeName, out var memberName)) { - var accessorType = Type.GetType(accessorTypeName, throwOnError: true); + var accessorType = Type.GetType(accessorTypeName, throwOnError: true)!; // if delegate, look for a method and then construct a delegate if (typeof(Delegate).IsAssignableFrom(toType) || typeof(MethodInfo) == toType) @@ -109,9 +109,7 @@ public StringArgumentValue(string providedValue) // is there a public static property with that name ? var publicStaticPropertyInfo = accessorType.GetTypeInfo().DeclaredProperties .Where(x => x.Name == memberName) - .Where(x => x.GetMethod != null) - .Where(x => x.GetMethod.IsPublic) - .FirstOrDefault(x => x.GetMethod.IsStatic); + .FirstOrDefault(x => x.GetMethod != null && x.GetMethod.IsPublic && x.GetMethod.IsStatic); if (publicStaticPropertyInfo != null) {