Skip to content
代码片段 群组 项目
未验证 提交 7bbda383 编辑于 作者: James Newton-King's avatar James Newton-King
浏览文件

Fix trimming warning

上级 0a87a4ad
No related branches found
No related tags found
无相关合并请求
...@@ -74,7 +74,7 @@ public sealed class ManagedAuthenticatedEncryptorFactory : IAuthenticatedEncrypt ...@@ -74,7 +74,7 @@ public sealed class ManagedAuthenticatedEncryptorFactory : IAuthenticatedEncrypt
} }
else else
{ {
return AlgorithmActivator.CreateFactory<KeyedHashAlgorithm>(configuration.ValidationAlgorithmType); return AlgorithmActivator.CreateFactory<KeyedHashAlgorithm>(ValidateHasPublicParameterlessConstructor(configuration.ValidationAlgorithmType));
} }
} }
...@@ -99,10 +99,23 @@ public sealed class ManagedAuthenticatedEncryptorFactory : IAuthenticatedEncrypt ...@@ -99,10 +99,23 @@ public sealed class ManagedAuthenticatedEncryptorFactory : IAuthenticatedEncrypt
} }
else else
{ {
return AlgorithmActivator.CreateFactory<SymmetricAlgorithm>(configuration.EncryptionAlgorithmType); return AlgorithmActivator.CreateFactory<SymmetricAlgorithm>(ValidateHasPublicParameterlessConstructor(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> /// <summary>
/// Contains helper methods for generating cryptographic algorithm factories. /// Contains helper methods for generating cryptographic algorithm factories.
/// </summary> /// </summary>
...@@ -111,7 +124,7 @@ public sealed class ManagedAuthenticatedEncryptorFactory : IAuthenticatedEncrypt ...@@ -111,7 +124,7 @@ public sealed class ManagedAuthenticatedEncryptorFactory : IAuthenticatedEncrypt
/// <summary> /// <summary>
/// Creates a factory that wraps a call to <see cref="Activator.CreateInstance{T}"/>. /// Creates a factory that wraps a call to <see cref="Activator.CreateInstance{T}"/>.
/// </summary> /// </summary>
public static Func<T> CreateFactory<T>(Type implementation) public static Func<T> CreateFactory<T>([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)] Type implementation)
{ {
return ((IActivator<T>)Activator.CreateInstance(typeof(AlgorithmActivatorCore<>).MakeGenericType(implementation))!).Creator; return ((IActivator<T>)Activator.CreateInstance(typeof(AlgorithmActivatorCore<>).MakeGenericType(implementation))!).Creator;
} }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册