【问题标题】:asp.net core and System.Security.Cryptography.Native.Appleasp.net 核心和 System.Security.Cryptography.Native.Apple
【发布时间】:2017-03-12 19:34:35
【问题描述】:

我在 macOS 上创建新的 AspNetCore 应用程序并添加 EF Core 包。 我尝试使用方法 SaveChanges()(DbContext 类)将数据保存到数据库中并得到下一个错误:

"System.DllNotFoundException: 无法加载 DLL 'System.Security.Cryptography.Native.Apple':指定模块 找不到。”

我使用以下说明安装 openssl:

  1. 酿造更新
  2. brew install openssl
  3. ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
  4. ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

操作系统:macOS(10.12.1)

project.json:

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Logging": "1.1.0-preview1-final",
    "Microsoft.Extensions.Logging.Console": "1.1.0-preview1-final",
    "Microsoft.Extensions.Logging.Debug": "1.1.0-preview1-final",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.1.0-preview1-final",
    "Microsoft.Extensions.Logging.Abstractions": "1.1.0-preview1-final",
    "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.2",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview3-final",
    "Npgsql.EntityFrameworkCore.PostgreSQL.Design": "1.0.2",
    "Microsoft.EntityFrameworkCore.Design": "1.1.0-preview1-final"
  },
  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0-preview3-final",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview3-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ],
      "buildOptions": {
        "emitEntryPoint": true
      }
    }
  },
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },
  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },
  "publishOptions": {
    "include": [
      "wwwroot",
      "**/*.cshtml",
      "appsettings.json",
      "web.config"
    ]
  },
  "scripts": {
    "postpublish": [
      "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
    ]
  },
  "tooling": {
    "defaultNamespace": "TTT"
  }
}

有人知道我做错了什么吗?

谢谢。

更新(添加堆栈跟踪信息)

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HL01MGG6QKIE": An unhandled exception was thrown by the application.
System.DllNotFoundException: Unable to load DLL 'System.Security.Cryptography.Native.Apple': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E)
   at Interop.AppleCrypto.DigestCreate(PAL_HashAlgorithm algorithm, Int32& cbDigest)
   at Internal.Cryptography.HashProviderDispenser.AppleDigestProvider..ctor(PAL_HashAlgorithm algorithm)
   at Internal.Cryptography.HashProviderDispenser.CreateHashProvider(String hashAlgorithmId)
   at System.Security.Cryptography.MD5.Implementation..ctor()
   at Npgsql.FrontendMessages.PasswordMessage.CreateMD5(String password, String username, Byte[] serverSalt)
   at Npgsql.NpgsqlConnector.ProcessAuthenticationMessage(String username, AuthenticationRequestMessage msg)
   at Npgsql.NpgsqlConnector.HandleAuthentication(String username, NpgsqlTimeout timeout)
   at Npgsql.NpgsqlConnector.Open(NpgsqlTimeout timeout)
   at Npgsql.ConnectorPool.Allocate(NpgsqlConnection conn, NpgsqlTimeout timeout)
   at Npgsql.NpgsqlConnection.OpenInternal()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open()
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransaction(IsolationLevel isolationLevel)
   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(Tuple`2 parameters)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IReadOnlyList`1 entriesToSave)
   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)
   at TTT.Controllers.ValuesController.Get(Int32 id) in /Users/cmaker-note/Projects/AspNetCore/TTT/Controllers/ValuesController.cs:line 26
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionFilterAsync>d__28.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeAsync>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.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.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.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.Server.Kestrel.Internal.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()

【问题讨论】:

标签: macos entity-framework asp.net-core entity-framework-core


【解决方案1】:

确定

ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/

实际上指向有效文件。 对我来说,自制软件安装了 openssl 包但没有链接它。 我相信是这样的:

brew link --force openssl

确实如此。但由于安全原因,自制软件拒绝自动执行此操作。因此,如果您只是想尝试 .NetCore,您可能只需指向实际的安装位置。即:

/usr/local/Cellar/openssl/1.0.2k

它在哪里适合我。

【讨论】:

    【解决方案2】:

    今晚更新时遇到了同样的问题

    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    

    "Microsoft.Extensions.Logging": "1.1.0-preview1-final",
    "Microsoft.Extensions.Logging.Console": "1.1.0-preview1-final",
    "Microsoft.Extensions.Logging.Debug": "1.1.0-preview1-final",
    

    当我将这三个版本都恢复到 1.0.0 版时,它又可以正常工作了。

    我升级的原因是因为我添加了对这个的引用

    "Microsoft.EntityFrameworkCore.Design": "1.1.0-preview1-final"
    

    它想要 1.1.* 版本的

    "Microsoft.Extensions.Logging"
    

    反正我降级了

    "Microsoft.EntityFrameworkCore.Design": "1.1.0-preview1-final"
    

    "Microsoft.EntityFrameworkCore.Design": "1.0.1"
    

    一切又对我有用。我希望这个问题会在 1.1.* 准备好迎接黄金时段时消失。

    【讨论】:

      【解决方案3】:

      我认为你错过了一步。这里是:

      brew link --force openssl
      

      所有步骤:

      brew update
      brew install openssl
      brew link --force openssl
      

      参考:dotnet restore (OSX)

      【讨论】:

      • 不,这对我没有帮助。在 exec command("brew link --force openssl") 之后,我收到消息:“链接仅桶装 openssl 意味着您最终可能会链接到不安全的...”。我开始寻找此消息并发现此问题github.com/dotnet/cli/issues/3964#issuecomment-236493536。我认为是链接错误。
      • 您是否也看到了我上面帖子中的参考链接?
      猜你喜欢
      • 2018-10-17
      • 1970-01-01
      • 2020-01-10
      • 2017-10-23
      • 2020-09-08
      • 2018-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多