Sdk: dotnet restore failing with "Unable to load DLL 'System.Security.Cryptography.Native'" on macosx

Created on 2 Apr 2016  路  22Comments  路  Source: dotnet/sdk

Steps to reproduce

/temp/hwapp$ dotnet new
/temp/hwapp$ dotnet restore
log : Restoring packages for /Users/xxx/temp/hwapp/project.json...
error: The type initializer for 'Crypto' threw an exception.
error: Unable to load DLL 'System.Security.Cryptography.Native': The specified module could not be found.
error: (Exception from HRESULT: 0x8007007E)

Expected behavior

I expected to get no error while restoring packages.

Actual behavior

Getting the error below while restoring packages:
error: The type initializer for 'Crypto' threw an exception.
error: Unable to load DLL 'System.Security.Cryptography.Native': The specified module could not be found.
error: (Exception from HRESULT: 0x8007007E)

Environment data

dotnet --info output:

/temp/hwapp$ dotnet --info
Unknown option: --info
.NET Command Line Tools (1.0.0-beta-001598)
Usage: dotnet [common-options] [command] [arguments]

Arguments:
  [command]     The command to execute
  [arguments]   Arguments to pass to the command

Common Options (passed before the command):
  -v|--verbose  Enable verbose output
  --version     Display .NET CLI Version Info

Common Commands:
  new           Initialize a basic .NET project
  restore       Restore dependencies specified in the .NET project
  build         Builds a .NET project
  publish       Publishes a .NET project for deployment (including the runtime)
  run           Compiles and immediately executes a .NET project
  repl          Launch an interactive session (read, eval, print, loop)
  pack          Creates a NuGet package

Operating system:
Darwin mak 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64

Installed OpenSSL with macports:

>sudo port installed | grep openssl
  openssl @1.0.1j_0+universal
  openssl @1.0.1k_0+universal
  openssl @1.0.2_0+universal
  openssl @1.0.2a_0+universal
  openssl @1.0.2d_0+universal
  openssl @1.0.2e_0+universal
  openssl @1.0.2f_0+universal
  openssl @1.0.2g_0+universal
  openssl @1.0.2g_0 (active)

Most helpful comment

@nicc777 it doesn't work for me... When i run this command i get
brew link --force openssl
Warning: Refusing to link: openssl
Linking keg-only OpenSSL means you may end up linking against the insecure,
deprecated system version while using the headers from the Homebrew version.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

All 22 comments

Installing openssl using homebrew worked for me

I really hope that macports is not the issue here, as it should be supported :) I will investigate further

@karimelm installing with homebrew openssl (openssl-1.0.2g.el_capitan.bottle.tar.gz) did the trick, now i can got rid of the issue related to Unable to load DLL 'System.Security.Cryptography.Native' . I wonder why dotnet/cli rely on homebrew and not on macports.

I continue to see the error even after installing openssl using brew - I must mention that, for me, brew installs everything in my home directory. Is there someway, I can provide LD_LIBRARY_PATH or something?

Problem solved for me :) .. adding soft links from /usr/local/opt to my homebrew did the trick

The dependency comes from https://github.com/dotnet/CoreFx. If you have suggestions on how to eliminate it, that's the right place!

@piotrpMSFT I just ran into this with the latest. To get around it I installed openssl via homebrew as mentioned above. Since we closed this, is this a known requirement to work with .NET on a mac or is there another way to enable this besides installing openssl?

I see that openssl is listed at http://dotnet.github.io/getting-started/ as a prereq for the OSX case. Ignore my previous question.

For future finders, not interacting well with macports or user-scoped-brew-install is tracked now at https://github.com/dotnet/corefx/issues/8124.

Remember to run brew link --force openssl

@nicc777 it doesn't work for me... When i run this command i get
brew link --force openssl
Warning: Refusing to link: openssl
Linking keg-only OpenSSL means you may end up linking against the insecure,
deprecated system version while using the headers from the Homebrew version.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

@nicc777 I have the same problem as @sleemer

@nicc777 I have the same problem as @lokinfey and @sleemer.

@nicc777 I have the same problem as @lokinfey, @sleemer and @themadbaron.

@sleemer @lokinfey @themadbaron @dvtodika - have a look at http://stackoverflow.com/questions/38670295/brew-refusing-to-link-openssl - this may help.

The recent change to homebrew is something that we're trying to follow up on.

I had the same problem... this works ;)

language: csharp
sudo: required
dist: trusty
env:

  • CLI_VERSION=latest
    addons:
    apt:
    packages:
- gettext
- libcurl4-openssl-dev
- libicu-dev
- libssl-dev
- libunwind8
- zlib1g

mono:

  • 4.2.3
    os:
  • linux
  • osx
    osx_image: xcode7.3
    branches:
    only:
- master
- dev

before_install:
- if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; brew link --force openssl; 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/; fi
....

or check here --> https://raw.githubusercontent.com/awes0mecoderz/retarder/master/.travis.yml

Instead of the ln instructions found here: https://www.microsoft.com/net/core#macos, I had to do the following:

ln -s /usr/local/homebrew/Cellar/openssl/1.0.2j/lib/libssl.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/homebrew/Cellar/openssl/1.0.2j/lib/libssl.1.0.0.dylib /usr/local/lib/

@samspot You'll want to find the path under opt, since that won't contain the patch version number and thus will get newer versions of the library when you upgrade:

bartonjs@jsb-mac:~/coreclr $ find -L `brew --prefix` -name libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2g/lib/libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2h_1/lib/libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2i/lib/libcrypto.1.0.0.dylib
/usr/local/Cellar/openssl/1.0.2j/lib/libcrypto.1.0.0.dylib
/usr/local/lib/libcrypto.1.0.0.dylib
/usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib

In my case here, the last entry. (The /usr/local/lib one is obviously wrong, since that's the one that you're trying to make, and the rest have version numbers in them)

I'm not sure I understand. It looks like you are redirecting me back to the original linking instructions, which I could not get to work even after trying several workarounds.

My output:

$ find -L brew --prefix -name libcrypto.1.0.0.dylib
/usr/local/homebrew/Cellar/openssl/1.0.2j/lib/libcrypto.1.0.0.dylib
/usr/local/homebrew/lib/libcrypto.1.0.0.dylib
/usr/local/homebrew/opt/openssl/lib/libcrypto.1.0.0.dylib
/usr/local/homebrew/var/homebrew/linked/openssl/lib/libcrypto.1.0.0.dylib

@samspot Right, so you want

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

Though since you already have symlinks there you either need to remove them first or use ln -sf instead of ln -s. Your opt directory is under /usr/local/homebrew instead of /usr/local. (Presumably brew --prefix for you reports /usr/local/homebrew?)

ok great, thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings