【问题标题】:Failed to load SNI.dll加载 SNI.dll 失败
【发布时间】:2020-03-17 01:28:14
【问题描述】:

我在 C# 中使用实体框架开发了一个 Web Api 项目,在 localhost 中执行该项目时,它工作正常。在将此项目传递给开发环境的 IIS 时,它也可以工作,但是当我将它传递给 QA 环境的 IIS 时,出现以下错误:

{
    "Message": "An error has occurred.",
    "ExceptionMessage": "The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception.",
    "ExceptionType": "System.TypeInitializationException",
    "StackTrace": "   at ConsultaCuentaCupon_Api.Controllers.ConsultaCuponClienteController.<Post>d__0.MoveNext() in C:\\Users\\nflores\\source\\repos\\ConsultaCuentaCupon-Api\\ConsultaCuentaCupon-Api\\Controllers\\ConsultaCuponClienteController.cs:line 53\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__1`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()",
    "InnerException": {
        "Message": "An error has occurred.",
        "ExceptionMessage": "The type initializer for 'Microsoft.Data.SqlClient.SNILoadHandle' threw an exception.",
        "ExceptionType": "System.TypeInitializationException",
        "StackTrace": "   at Microsoft.Data.SqlClient.TdsParser..cctor() in E:\\agent1\\_work\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\Microsoft\\Data\\SqlClient\\TdsParser.cs:line 156",
        "InnerException": {
            "Message": "An error has occurred.",
            "ExceptionMessage": "The type initializer for 'Microsoft.Data.SqlClient.SNINativeMethodWrapper' threw an exception.",
            "ExceptionType": "System.TypeInitializationException",
            "StackTrace": "   at Microsoft.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize()\r\n   at Microsoft.Data.SqlClient.SNILoadHandle..ctor() in E:\\agent1\\_work\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\Microsoft\\Data\\SqlClient\\TdsParserSafeHandles.cs:line 31\r\n   at Microsoft.Data.SqlClient.SNILoadHandle..cctor() in E:\\agent1\\_work\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\Microsoft\\Data\\SqlClient\\TdsParserSafeHandles.cs:line 16",
            "InnerException": {
                "Message": "An error has occurred.",
                "ExceptionMessage": "Failed to load C:\\inetpub\\wwwroot\\CuponCliente-API\\bin\\x64\\SNI.dll",
                "ExceptionType": "System.ComponentModel.Win32Exception",
                "StackTrace": "   at Microsoft.Data.SqlClient.SNINativeMethodWrapper..cctor() in E:\\agent1\\_work\\34\\s\\src\\Microsoft.Data.SqlClient\\netfx\\src\\Microsoft\\Data\\Interop\\SNINativeMethodWrapper.cs:line 66"
            }
        }
    }
}

一直在寻找此错误及其可能的解决方案,我尝试了多种解决方案,但错误仍然存​​在。如果有人已经经历过这种情况,我将非常感谢您的帮助。

【问题讨论】:

    标签: c# entity-framework ado.net


    【解决方案1】:

    我必须在服务器上安装“Microsoft Visual C++ 2015-2019 Redistributable”(在我的情况下为 x64),但它无法处理您提到的错误消息。

    【讨论】:

    【解决方案2】:

    我对这个错误有不同的情况,也许它可以帮助某人:

    • 我在 IIS(Internet 信息服务器)中运行 Web 应用程序
    • 应用程序池是使用我的凭据设置的
    • 我上周更改了密码

    结果是应用程序仍在启动, 但是在尝试连接数据库时出现了这个令人困惑的异常:

    Failed to load SNI.dll not found or pemission denied
    

    删除 App-Pool 用户并使用新密码重新输入有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-04
      • 2019-07-03
      • 2020-10-26
      • 2013-02-08
      • 2014-01-31
      相关资源
      最近更新 更多