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

entity-framework – 将ASP.NET Core EF发布到Azure无法加载DLL’sni.dll’

使用EF将ASP.NET Core应用程序发布到Azure Web App时,在连接Sql Server时会出现此错误

info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
      Executing action method SearchDocumentsWebApp.Controllers.SearchApiController.SearchByTopic (SearchDocumentsWebApp) with arguments (info) - ModelState is Valid
warn: Microsoft.EntityFrameworkCore.Query.Internal.sqlServerQueryCompilationContextFactory[8]
      The LINQ expression '[e].Id.Equals(__email_0,CurrentCultureIgnoreCase)' Could not be translated and will be evaluated locally. To configure this warning use the DbContextOptionsBuilder.ConfigureWarnings API (event id 'RelationalEventId.QueryClientEvaluationWarning'). ConfigureWarnings can be used when overriding the DbContext.OnConfiguring method or using AddDbContext on the application service provider.
warn: Microsoft.EntityFrameworkCore.Query.Internal.sqlServerQueryCompilationContextFactory[8]
      The LINQ expression 'SingleOrDefault()' Could not be translated and will be evaluated locally. To configure this warning use the DbContextOptionsBuilder.ConfigureWarnings API (event id 'RelationalEventId.QueryClientEvaluationWarning'). ConfigureWarnings can be used when overriding the DbContext.OnConfiguring method or using AddDbContext on the application service provider.
fail: Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler[1]
      An exception occurred in the database while iterating the results of a query.
      System.TypeInitializationException: The type initializer for 'System.Data.sqlClient.TdsParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.sqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'sni.dll': The specified module Could not be found. (Exception from HRESULT: 0x8007007E)
         at System.Data.sqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
         at System.Data.sqlClient.SNILoadHandle..ctor()
         at System.Data.sqlClient.SNILoadHandle..cctor()
         --- End of inner exception stack trace ---
         at System.Data.sqlClient.TdsParser..cctor()
         --- End of inner exception stack trace ---
         at System.Data.sqlClient.TdsParser..ctor(Boolean MARS,Boolean fAsynchronous)
         at System.Data.sqlClient.sqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,Boolean redirectedUserInstance,sqlConnectionString connectionoptions,TimeoutTimer timeout)
         at System.Data.sqlClient.sqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout,Boolean redirectedUserInstance)
         at System.Data.sqlClient.sqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,Object providerInfo,sqlConnectionString userConnectionoptions,SessionData reconnectSessionData,Boolean applyTransientFaultHandling)
         at System.Data.sqlClient.sqlConnectionFactory.CreateConnection(DbConnectionoptions options,DbConnectionPoolKey poolKey,Object poolGroupProviderInfo,DbConnectionPool pool,DbConnection owningConnection,DbConnectionoptions userOptions)
         at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool,DbConnection owningObject,DbConnectionoptions options,DbConnectionoptions userOptions)
         at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionoptions userOptions,DbConnectionInternal oldConnection)
         at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionInternal oldConnection)
         at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,Boolean allowCreate,Boolean onlyOneCheckConnection,DbConnectionInternal& connection)
         at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,taskcompletionsource`1 retry,DbConnectionInternal& connection)
         at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,DbConnectionInternal oldConnection,DbConnectionInternal& connection)
         at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionFactory connectionFactory,DbConnectionoptions userOptions)
         at System.Data.sqlClient.sqlConnection.TryOpen(taskcompletionsource`1 retry)
         at System.Data.sqlClient.sqlConnection.open()
         at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.open()
         at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer)
         at Microsoft.EntityFrameworkCore.Storage.Internal.sqlServerExecutionStrategy.Execute[TState,TResult](Func`2 operation,Func`2 verifySucceeded,TState state)
         at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
         at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
         at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
         at lambda_method(Closure,QueryContext )
         at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__displayClass20_0`1.<CompileQueryCore>b__0(QueryContext qc)
System.TypeInitializationException: The type initializer for 'System.Data.sqlClient.TdsParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.sqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'sni.dll': The specified module Could not be found. (Exception from HRESULT: 0x8007007E)
   at System.Data.sqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
   at System.Data.sqlClient.SNILoadHandle..ctor()
   at System.Data.sqlClient.SNILoadHandle..cctor()
   --- End of inner exception stack trace ---
   at System.Data.sqlClient.TdsParser..cctor()
   --- End of inner exception stack trace ---
   at System.Data.sqlClient.TdsParser..ctor(Boolean MARS,Boolean fAsynchronous)
   at System.Data.sqlClient.sqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,TimeoutTimer timeout)
   at System.Data.sqlClient.sqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout,Boolean redirectedUserInstance)
   at System.Data.sqlClient.sqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity,Boolean applyTransientFaultHandling)
   at System.Data.sqlClient.sqlConnectionFactory.CreateConnection(DbConnectionoptions options,DbConnectionoptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool,DbConnectionoptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection,DbConnectionoptions userOptions)
   at System.Data.sqlClient.sqlConnection.TryOpen(taskcompletionsource`1 retry)
   at System.Data.sqlClient.sqlConnection.open()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.open()
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable.Enumerator.BufferlessMoveNext(Boolean buffer)
   at Microsoft.EntityFrameworkCore.Storage.Internal.sqlServerExecutionStrategy.Execute[TState,TState state)
   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_ShapedQuery>d__3`1.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at lambda_method(Closure,QueryContext )
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__displayClass20_0`1.<CompileQueryCore>b__0(QueryContext qc)
info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
      Executed action SearchDocumentsWebApp.Controllers.SearchApiController.SearchByTopic (SearchDocumentsWebApp) in 3176.7883ms
fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[0]
      An unhandled exception has occurred: The type initializer for 'System.Data.sqlClient.TdsParser' threw an exception.
System.TypeInitializationException: The type initializer for 'System.Data.sqlClient.TdsParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.sqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'sni.dll': The specified module Could not be found. (Exception from HRESULT: 0x8007007E)
   at System.Data.sqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
   at System.Data.sqlClient.SNILoadHandle..ctor()
   at System.Data.sqlClient.SNILoadHandle..cctor()
   --- End of inner exception stack trace ---
   at System.Data.sqlClient.TdsParser..cctor()
   --- End of inner exception stack trace ---
   at System.Data.sqlClient.TdsParser..ctor(Boolean MARS,QueryContext )
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__displayClass20_0`1.<CompileQueryCore>b__0(QueryContext qc)
   at SearchDocumentsWebApp.Controllers.SearchApiController.<SearchByTopic>d__8.MoveNext() in C:\Users\gubert\Source\Repos\Amdocs\SearchDocumentsWebApp\src\SearchDocumentsWebApp\Controllers\SearchAPIController.cs:line 76
--- End of stack trace from prevIoUs location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextActionFilterasync>d__25.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next,Scope& scope,Object& state,Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeNextResourceFilter>d__22.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next,Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>d__20.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware`1.<Invoke>d__18.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.<Invoke>d__7.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.ApplicationInsights.AspNetCore.RequestTrackingMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from prevIoUs location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>d__6.MoveNext()

这是我的project.json:

{
  "buildOptions": {
    "emitEntryPoint": true,"preserveCompilationContext": true
  },"dependencies": {
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.2","Microsoft.AspNetCore.Authentication.Cookies": "1.1.0","Microsoft.AspNetCore.Authentication.OpenIdConnect": "1.1.0","Microsoft.AspNetCore.Authorization": "1.1.0","Microsoft.AspNetCore.Diagnostics": "1.1.0","Microsoft.AspNetCore.Mvc": "1.1.0","Microsoft.AspNetCore.Mvc.Core": "1.1.0","Microsoft.AspNetCore.Mvc.TagHelpers": "1.1.0","Microsoft.AspNetCore.Server.IISIntegration": "1.1.0","Microsoft.AspNetCore.Server.Kestrel": "1.1.0","Microsoft.AspNetCore.StaticFiles": "1.1.0","Microsoft.EntityFrameworkCore.Design": "1.1.0","Microsoft.EntityFrameworkCore.sqlServer": "1.1.0","Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final","Microsoft.Extensions.Configuration.Binder": "1.1.0","Microsoft.Extensions.Configuration.Environmentvariables": "1.1.0","Microsoft.Extensions.Configuration.FileExtensions": "1.1.0","Microsoft.Extensions.Configuration.Json": "1.1.0","Microsoft.Extensions.Logging": "1.1.0","Microsoft.Extensions.Logging.Console": "1.1.0","Microsoft.Extensions.Logging.Debug": "1.1.0","Microsoft.IdentityModel.Protocols.OpenIdConnect": "2.1.0","Microsoft.NETCore.App": "1.1.0","Microsoft.VisualStudio.Web.browserLink.Loader": "14.1.0","Newtonsoft.Json": "9.0.2-beta1","WindowsAzure.Storage": "7.2.1"
  },"frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6","dnxcore50","portable-net45+win8"
      ]
    }
  },"publishOptions": {
    "include": [
      "wwwroot","Views","web.config","appsettings.json","appsettings.*.json","LICENSE.txt"
    ]
  },"runtimeOptions": {
    "gcServer": true
  },"runtimes": {
    "win10-x64": {}
  },"scripts": {
    //"prepublish": [ "npm install","npm recompileapp" ],"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },"tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final","Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final","type": "platform","imports": [
        "portable-net45+win8+dnxcore50","portable-net45+win8"
      ]

    }
  }
}

我甚至试图将“Microsoft.EntityFrameworkCore.Tools”的“type”属性更改为“platform”,这样它就会复制它的dll,还试图将“System.Data.sqlClient.dll”复制到/ wwwroot / bin文件夹重新启动应用程序但仍然得到相同的错误.

在我的本地机器上它工作

解决方法

解决了!

azure web apps在Windows 2012 r2上运行,所以我需要设置win7运行时并将发布设置更改为win7-x64:

"runtimes": {
    "win10-x64": {},"win7-x64": {}
  },

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

相关推荐