dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.75k stars 1.07k forks source link

Entity framework produces libSystem.native error #24697

Open anthonystanton opened 2 years ago

anthonystanton commented 2 years ago

Is there an existing issue for this?

Describe the bug

Currently trying to add a migration in .net 5 however, when I try to do so, I am given the following error:

Unhandled exception. System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Tools.AnsiConsole' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'System.Native' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libSystem.Native, 1): image not found
   at Interop.Sys.Dup(SafeFileHandle oldfd)
   at System.ConsolePal.<>c.<OpenStandardOutput>b__9_0()
   at Microsoft.Win32.SafeHandles.SafeFileHandleHelper.Open(Func`1 fdFunc)
   at System.ConsolePal.OpenStandardOutput()
   at System.Console.<>c.<get_Out>b__26_0()
   at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Object& syncLock, Func`1 valueFactory)
   at System.Threading.LazyInitializer.EnsureInitialized[T](T& target, Object& syncLock, Func`1 valueFactory)
   at System.Console.get_Out()
   at Microsoft.EntityFrameworkCore.Tools.AnsiConsole..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.EntityFrameworkCore.Tools.AnsiConsole.WriteLine(String text)
   at Microsoft.EntityFrameworkCore.Tools.Reporter.WriteLine(String value)
   at Microsoft.EntityFrameworkCore.Tools.Reporter.WriteInformation(String message)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)

I was able to add migrations a week ago however, I have recently tried it and am presented with this error. I have tried uninstalling and reinstalling entity framework packages, uninstalling and reinstalling visual studio. But I am still unable to get this working. Is there any suggestions?

The only thing I can possibly think of is my app updated to .net 5.0.406 within the last week so this may be something which has had an impact?

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

.5.0.406

Anything else?

VS for Mac 2019

.NET SDK (reflecting any global.json): Version: 5.0.406 Commit: 3a48fd6fe5

Runtime Environment: OS Name: Mac OS X OS Version: 10.13 OS Platform: Darwin RID: osx.10.13-x64 Base Path: /usr/local/share/dotnet/sdk/5.0.406/

Host (useful for support): Version: 5.0.15 Commit: 3065735be7

.NET SDKs installed: 3.1.410 [/usr/local/share/dotnet/sdk] 3.1.411 [/usr/local/share/dotnet/sdk] 3.1.416 [/usr/local/share/dotnet/sdk] 3.1.417 [/usr/local/share/dotnet/sdk] 5.0.301 [/usr/local/share/dotnet/sdk] 5.0.302 [/usr/local/share/dotnet/sdk] 5.0.404 [/usr/local/share/dotnet/sdk] 5.0.405 [/usr/local/share/dotnet/sdk] 5.0.406 [/usr/local/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.16 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.17 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.22 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.23 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.14 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.16 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.17 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.22 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.23 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.14 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

sfratt commented 2 years ago

Same issue for me. I also am on macOS 10.13 and recently updated to .NET SDK 5.0.406.

anthonystanton commented 2 years ago

Tried uninstalling latest .NET SDK and Runtime however still get the error.

@sfratt Have you had any luck with any solutions?

ajcvickers commented 2 years ago

This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

iezed commented 2 years ago

Hi, it also happens by launching dotnet ef, without project, on macOS 10.13.

anthonystanton commented 2 years ago

This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

As @iezed has said, simply launching dotnet ef produces this error.

A brand new project with no added code will produce the same error when launching dotnet ef.

iezed commented 2 years ago

The bug appeared with the recent version of net SDK 3.1.417 on mac 10.13, it's not relate at donet 5 o 6. Sorry for my bad english.

Describe the bug

System.DllNotFoundException: "Unable to load shared library 'System.Native' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libSystem.Native, 1): image not found"

sfratt commented 2 years ago

@anthonystanton I also tried uninstalling the .NET 5.0.406 SDK and dotnet-ef tool of the same version with no luck.

@iezed did uninstalling the 3.1.417 SDK resolve the issue for you?

iezed commented 2 years ago

Yes, it's work! I removed all SDKs and reinstalled only 6.0.201 SDK. I'm going to do more tests.

anthonystanton commented 2 years ago

Tried uninstalling all versions of SDK and installed SDK 5.0.302 and still having the same issue.

@sfratt Have you had any luck resolving this?

sfratt commented 2 years ago

@anthonystanton I uninstalled all .NET SDKs on my machine and kept just the latest .NET SDK 5.0.406 + .NET 5.0.15 runtime. Reinstalled dotnet-ef 5.0.15 and it worked again for me.

ajcvickers commented 2 years ago

Moving to the SDK repo since this does not seem to be an EF-specific bug. but rather an issue with the SDK installed.

mdashiqu commented 2 weeks ago

my mac version is 10.13.6 and i am getting this error

Unhandled exception. System.DllNotFoundException: Unable to load shared library 'System.Native' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libSystem.Native, 1): image not found at Interop.Sys.Stat(String path, FileStatus& output) at Internal.IO.File.InternalExists(String fullPath) at Internal.IO.File.Exists(String path) at System.TimeZoneInfo.TryLoadTzFile(String tzFilePath, Byte[]& rawData, String& id) at System.TimeZoneInfo.TryGetLocalTzFile(Byte[]& rawData, String& id) at System.TimeZoneInfo.GetLocalTimeZoneFromTzFile() at System.TimeZoneInfo.CachedData.CreateLocal() at System.DateTime.get_Now() at Crawler_WinApp.Program.Exceptionlog(Exception ex) at Crawler_WinApp.Program.Main() Abort trap: 6

can anyone help what is the actual problem and i run dotnet 3.1,5.1,6.1 but still same issue