Skip to content
Prev Previous commit
Next Next commit
Revert "Fix trimming warning"
This reverts commit 7bbda38.
  • Loading branch information
JamesNK committed Sep 13, 2022
commit 0992bedc12cf58d0dbe3dccc7d9694ea02ee6796
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private Func<KeyedHashAlgorithm> GetKeyedHashAlgorithmFactory(ManagedAuthenticat
}
else
{
return AlgorithmActivator.CreateFactory<KeyedHashAlgorithm>(ValidateHasPublicParameterlessConstructor(configuration.ValidationAlgorithmType));
return AlgorithmActivator.CreateFactory<KeyedHashAlgorithm>(configuration.ValidationAlgorithmType);
}
}

Expand All @@ -99,23 +99,10 @@ private Func<SymmetricAlgorithm> GetSymmetricBlockCipherAlgorithmFactory(Managed
}
else
{
return AlgorithmActivator.CreateFactory<SymmetricAlgorithm>(ValidateHasPublicParameterlessConstructor(configuration.EncryptionAlgorithmType));
return AlgorithmActivator.CreateFactory<SymmetricAlgorithm>(configuration.EncryptionAlgorithmType);
}
}

[UnconditionalSuppressMessage("Trimmer", "IL2068", Justification = "Reflecting over the async Task types contract")]
[UnconditionalSuppressMessage("Trimmer", "IL2070", Justification = "Reflecting over the async Task types contract")]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
private static Type ValidateHasPublicParameterlessConstructor(Type type)
{
if (type.GetConstructor(Type.EmptyTypes) == null)
{
throw new InvalidOperationException($"Unable to find public parameterless constructor for type '{type.FullName}'. If the app is published with trimming then it may have been trimmed. Ensure the type's assembly is excluded from trimming.");
}

return type;
}

/// <summary>
/// Contains helper methods for generating cryptographic algorithm factories.
/// </summary>
Expand All @@ -124,7 +111,7 @@ private static class AlgorithmActivator
/// <summary>
/// Creates a factory that wraps a call to <see cref="Activator.CreateInstance{T}"/>.
/// </summary>
public static Func<T> CreateFactory<T>([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type implementation)
public static Func<T> CreateFactory<T>(Type implementation)
{
return ((IActivator<T>)Activator.CreateInstance(typeof(AlgorithmActivatorCore<>).MakeGenericType(implementation))!).Creator;
}
Expand Down