微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

System.Security.Cryptography.CryptographicException:加密操作期间发生错误

如何解决System.Security.Cryptography.CryptographicException:加密操作期间发生错误

我最近在我的开发 API 服务器上安装了 stackify,我在 stackify 错误仪表板上出现了这个错误,但我无法重现该错误。我相信几乎每个向 API 发出的请求都会记录一个错误,即使所有请求都正常(200)并且没有响应 ServerError(5XX)。

这是错误信息:

System.Security.Cryptography.CryptographicException:System.Security.Cryptography.CryptographicException:加密操作期间发生错误。 在 System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.HomogenizeErrors(Func`2 func,Byte[] input)

错误文档:

{
  "id": "1266b838-a261-4bde-9220-ff7993d72c0e","env": "dev","host": "raidsrv3","appname": "environment.appname.com","version": null,"apploc": "D:\\StageApplications\\environment.appname.com","message": "System.NullReferenceException: Object reference not set to an instance of an object.\r\nSystem.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object.\r\n  at lambda_method(Closure,Loginviewmodel )\r\n","json": null,"jsonPreview": null,"thread": "40","threadOs": null,"transid": "7af3de61-9bf1-43d8-b60c-ff9850a35490","timestamp": "2021-01-20T14:21:41.247Z","inserted": "2021-01-20T14:22:11.8261135Z","level": "ERROR","logType": "app-dotnet","logger": null,"urlRoute": "Home.Login","urlFull": null,"sourcemethod": "lambda_method(Closure,Loginviewmodel )","sourceline": null,"stackify": {
    "CdWebAppId": null,"CdId": 1,"CdAppId": 215,"Error": 1,"WebLogUrlId": null,"Queued": "2021-01-20T14:21:47.0806791Z","Tooksecs": 24.745,"QueuedPartition": "Jan201400p1","Trace": null,"FromApm": null,"Order": 1,"InvalidEpochStr": null,"IsWebLog": false,"AppNameId": "23f72352-2d5a-eb11-a607-0003ffcfb91b","AppEnvId": "43f72352-2d5a-eb11-a607-0003ffcfb91b","EnvId": 2,"Timestamp1M": "2021-01-20T14:21:00Z","Timestamp5M": "2021-01-20T14:20:00Z","Timestamp1H": "2021-01-20T14:00:00Z","Timestamp1D": "2021-01-20T00:00:00Z","IsProd": true,"Expiration1D": "2021-02-05T00:00:00Z","DeploymentId": null
  },"error": {
    "StackifyErrorID": "1266b838-a261-4bde-9220-ff7993d72c0e","OccurredEpochMillis": 1611152501247,"Error": {
      "InnerError": null,"StackTrace": [
        {
          "LineNum": null,"Method": "lambda_method(Closure,"CodeFileName": null
        }
      ],"Message": "System.NullReferenceException: Object reference not set to an instance of an object.","ErrorType": "System.NullReferenceException","ErrorTypeCode": "-2147467261","Data": null,"SourceMethod": "lambda_method(Closure,Loginviewmodel )"
    },"data": {},"EnvironmentDetail": {
      "DeviceName": "RAIDSRV3","AppLocation": "D:\\StageApplications\\environment.appname.com","AppName": "environment.appname.com","WebAppID": null,"ConfiguredAppName": null,"ConfiguredEnvironmentName": null,"ConfiguredLocationName": null,"IsAzureWorkerRole": false
    },"WebRequestDetail": {
      "UserIPAddress": null,"HttpMethod": "GET","RequestProtocol": null,"WebLogUrl": "Home.Login","RequestDomain": "environment.appname.com","ReportingUrl": "Home.Login","UrlKey": "get-home.login","RequestUrl": "https://environment.appname.com/","RequestUrlRoot": null,"RequestRoute": null,"ReferralUrl": null,"UserAgent": null,"Headers": {},"Cookies": {},"QueryString": {},"PostData": {},"SessionData": {},"PostDataraw": null,"MvcAction": null,"MvcController": null,"MvcArea": null
    },"apiclient": {
      "Name": null,"Platform": ".net"
    },"ServerVariables": {},"CustomerName": null,"UserName": null,"errorGroupId": "b772fbd6-db5a-eb11-a607-0003ffcfb91b","errorGroupInstanceId": "bf72fbd6-db5a-eb11-a607-0003ffcfb91b","displayMethodId": "d65c87ef-ca5a-eb11-a607-0003ffcfb91b","errorSourceMethodId": "d65c87ef-ca5a-eb11-a607-0003ffcfb91b","errorTypeMessageId": "2-df28da1c-715a-eb11-a607-0003ffcfb91b-0e8ec107143a2e3d04bfee99e49c20a5","errorUniqueId": "d75c87ef-ca5a-eb11-a607-0003ffcfb91b","errorPlatformTypeId": 2,"errorStateId": 0,"errorTypeId": "df28da1c-715a-eb11-a607-0003ffcfb91b","message": "System.NullReferenceException: Object reference not set to an instance of an object.","errorType": "System.NullReferenceException","errorTypeClass": "NullReferenceException","errorTypeCode": "-2147467261","sourceMethodName": "lambda_method(Closure,"sourceMethodShort": "lambda_method(Closure,"errorGroupCreatedUtc": "2021-01-20T04:55:18.767","displayMethodName": "lambda_method(Closure,"displayMethodShort": "lambda_method(Closure,"stackTraceHash": "858F2DB7DA4C81444B39BA60C9CC5B65","stackTrace": "System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object.\n\tat lambda_method(Closure,Loginviewmodel )\n","appended": "2021-01-20T14:22:22.5880117Z"
  },"winevent": null,"weblog": null,"tag": [
    "fromapm"
  ],"container": null,"kubernetes": null
}

我已经搜索了所有内容,但找不到此错误的解释。

以下是关于我的开发环境的一些背景信息:

  • API 是 .net Framework 4.7.2
  • 我将所有 nuget 包和库更新到了最新支持的版本
  • 机器密钥已配置,我已验证两个 API 服务器 web.config 文件中存在相同的密钥。例如:<machineKey validationKey="***" decryptionKey="***" />
  • API 部署在 2 个服务器上,Nginx 位于客户端和服务器之间。
  • Ocotopus Deploy 用于部署 API
  • DFS 用于将应用程序文件从主服务器同步到姊妹服务器

任何帮助将不胜感激!

解决方法

事实证明,stackify 捕获的这个异常是在 .net 框架内处理的 First Chance 异常。

在此答案中详细了解第一次机会例外here

如果您和我一样,并且您的组织担心 Stackify 捕获的所有异常,您可以转到环境设置 > 编辑环境 > 通过 APM 自动收集和查看应用程序错误,然后将设置从 将所有错误上传到错误模块 将未处理的错误上传到错误模块。

enter image description here

这将确保只有未处理的异常冒泡到 stackify 中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。