diff --git a/src/Shared/ActivatorUtilities/ActivatorUtilities.cs b/src/Shared/ActivatorUtilities/ActivatorUtilities.cs index aeafb6c0a190..e413b06ef913 100644 --- a/src/Shared/ActivatorUtilities/ActivatorUtilities.cs +++ b/src/Shared/ActivatorUtilities/ActivatorUtilities.cs @@ -51,33 +51,30 @@ public static object CreateInstance(IServiceProvider provider, Type instanceType { foreach (var constructor in instanceType.GetConstructors()) { - if (!constructor.IsStatic) - { - var matcher = new ConstructorMatcher(constructor); - var isPreferred = constructor.IsDefined(typeof(ActivatorUtilitiesConstructorAttribute), false); - var length = matcher.Match(parameters); + var matcher = new ConstructorMatcher(constructor); + var isPreferred = constructor.IsDefined(typeof(ActivatorUtilitiesConstructorAttribute), false); + var length = matcher.Match(parameters); - if (isPreferred) + if (isPreferred) + { + if (seenPreferred) { - if (seenPreferred) - { - ThrowMultipleCtorsMarkedWithAttributeException(); - } - - if (length == -1) - { - ThrowMarkedCtorDoesNotTakeAllProvidedArguments(); - } + ThrowMultipleCtorsMarkedWithAttributeException(); } - if (isPreferred || bestLength < length) + if (length == -1) { - bestLength = length; - bestMatcher = matcher; + ThrowMarkedCtorDoesNotTakeAllProvidedArguments(); } + } - seenPreferred |= isPreferred; + if (isPreferred || bestLength < length) + { + bestLength = length; + bestMatcher = matcher; } + + seenPreferred |= isPreferred; } } @@ -237,11 +234,6 @@ private static bool TryFindMatchingConstructor( { foreach (var constructor in instanceType.GetConstructors()) { - if (constructor.IsStatic) - { - continue; - } - if (TryCreateParameterMap(constructor.GetParameters(), argumentTypes, out int?[] tempParameterMap)) { if (matchingConstructor != null) @@ -267,11 +259,6 @@ private static bool TryFindPreferredConstructor( var seenPreferred = false; foreach (var constructor in instanceType.GetConstructors()) { - if (constructor.IsStatic) - { - continue; - } - if (constructor.IsDefined(typeof(ActivatorUtilitiesConstructorAttribute), false)) { if (seenPreferred)