C# Exception has been thrown by the target of an invocation(调用的目标已抛出异常) 解决办法

最近在做一个WPF项目时,部分电脑出现了Exception has been thrown by the target of an invocation的异常 (再次遇见,之前是winform)。

原因分析:

Windows 平台启用了FIPS验证加密算法,而代码中使用System.Security中的加密方法导致。
当然这不是导致这个异常的唯一原因,也有可能Net Framework环境引起的异常。

解决方法:

1.打开注册表编辑器

2.根据以下路径找到FipsAlgorithmPolicy
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy

3.修改Enabled的值为0(有些机器默认为1)

4.重启应用会发现问题解决(无需重启电脑)

posted @ 2020-01-09 09:07  Uniqueness  阅读(17444)  评论(0编辑  收藏  举报