Core: run dotnet on macos Sierra

Created on 20 Aug 2016  路  5Comments  路  Source: dotnet/core

when I restore, error! what's wrong with it?

xxxxMacBook-Pro:EmptyWeb1 zsc$ dotnet restore

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Crypto' threw an exception. ---> System.TypeInitializationException: The type initializer for 'CryptoInitializer' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'System.Security.Cryptography.Native': The specified module could not be found.
(Exception from HRESULT: 0x8007007E)
at Interop.CryptoInitializer.EnsureOpenSslInitialized()
at Interop.CryptoInitializer..cctor()
--- End of inner exception stack trace ---
at Interop.Crypto..cctor()
--- End of inner exception stack trace ---
at Interop.Crypto.GetRandomBytes(Byte* buf, Int32 num)
at System.IO.Path.GetCryptoRandomBytes(Byte* bytes, Int32 byteCount)
at System.IO.Path.GetRandomFileName()
at Microsoft.DotNet.InternalAbstractions.TemporaryDirectory..ctor()
at Microsoft.Extensions.EnvironmentAbstractions.DirectoryWrapper.CreateTemporaryDirectory()
at Microsoft.DotNet.Configurer.NuGetPackagesArchiver..ctor()
at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
at Microsoft.DotNet.Cli.Program.Main(String[] args)
Abort trap: 6

Most helpful comment

Also, I just found this:

https://docs.microsoft.com/en-us/dotnet/articles/core/getting-started

At the bottom of that page, it indicates that Sierra is not (officially) supported yet, but will be soon. That document was last modified on 08 Aug 2016. I have been running it successfully on Sierra but a build of the native runtime libraries doesn't exist for the platform (yet).

If you run dotnet --info, you can see the runtime identifier (RID): osx.10.12-x64

If you try to restore a project.json with an RID of osx.10.12-x64 you will get errors as follows:

Microsoft.Win32.Primitives 4.0.1 provides a compile-time reference assembly for Microsoft.Win32.Primitives on .NETCoreApp,Version=v1.0, but there is no run-time assembly compatible with osx.10.12-x64.

All 5 comments

The version of OpenSSL that is included in macOS Sierra (and previous versions) uses a custom crypto library, which is why you need to install OpenSSL via brew (or some other alternative) and then force link the crypto library:

Follow the directions here:

https://www.microsoft.com/net/core#macos

This should solve your issue.

Also, I just found this:

https://docs.microsoft.com/en-us/dotnet/articles/core/getting-started

At the bottom of that page, it indicates that Sierra is not (officially) supported yet, but will be soon. That document was last modified on 08 Aug 2016. I have been running it successfully on Sierra but a build of the native runtime libraries doesn't exist for the platform (yet).

If you run dotnet --info, you can see the runtime identifier (RID): osx.10.12-x64

If you try to restore a project.json with an RID of osx.10.12-x64 you will get errors as follows:

Microsoft.Win32.Primitives 4.0.1 provides a compile-time reference assembly for Microsoft.Win32.Primitives on .NETCoreApp,Version=v1.0, but there is no run-time assembly compatible with osx.10.12-x64.

As @dmccaffery indicated, this is a known issue and OpenSSL is needed. I will close this issue. If you still require help, please reopen the issue on the dotnet/cli repo. Thanks!

Thank you! Hope support Sierra as soon as possible

In case Google brings anyone else here...

Problem

I had been using macOS Sierra for some time with .NET Core without issues. I never saw the aforementioned warning at the bottom of the getting started page before today. This morning I updated to macOS Sierra 10.12.1, and now I cannot run my xUnit test suites locally. About 95% of the time, I get the following errors whenever I try to run them, even when I comment out every test in the suite:

> dotnet test ./test/MyProject.WebApi.Tests/
Project MyProject.WebApi (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
Project MyProject.WebApi.Tests (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
xUnit.net .NET CLI test runner (64-bit .NET Core osx.10.12-x64)
  Discovering: MyProject.WebApi.Tests
System.Threading.Tasks.TaskSchedulerException: An exception was thrown by a TaskScheduler.
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
SUMMARY: Total: 1 targets, Passed: 0, Failed: 1.

I can still perform dotnet run for the web api natively, but tests are a no go. Researching this issue is what brought me here, giving me the realization only now that I have been running .NET Core for quite some time on an unsupported version of macOS.

Workaround

Fortunately, Docker for Mac is quite stable these days and makes for a somewhat simple workaround. Using the microsoft/dotnet image, I ran the following to get a shell:

docker run -it --name dotnet --volume /path/to/MyProjectDirectory/:/MyProjectDirectory microsoft/dotnet:1.0.0-preview2-sdk bash

Then within the container:

cd /MyProjectDirectory
dotnet restore
dotnet test ./test/MyProject.WebApi.Tests
Was this page helpful?
0 / 5 - 0 ratings