Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeLibraryLoader throws exception on .NET 6 Mac Monterey application #457

Open
guillemcaldu-popcore opened this issue Jul 17, 2022 · 2 comments

Comments

@guillemcaldu-popcore
Copy link

guillemcaldu-popcore commented Jul 17, 2022

When trying to build a create a window in a .NET 6 on a Mac Pro M1 with OS Monterey (12.4) the following exception is thrown.

System.TypeInitializationException: The type initializer for 'Veldrid.Sdl2.Sdl2Native' threw an exception.
 ---> System.IO.FileNotFoundException: Could not find or load the native library from any name: [ libsdl2.dylib ]
   at NativeLibraryLoader.LibraryLoader.LoadNativeLibrary(String[] names, PathResolver pathResolver)
   at NativeLibraryLoader.NativeLibrary..ctor(String[] names, LibraryLoader loader, PathResolver pathResolver)
   at NativeLibraryLoader.NativeLibrary..ctor(String[] names)
   at Veldrid.Sdl2.Sdl2Native.LoadSdl2()
   at Veldrid.Sdl2.Sdl2Native..cctor()
   --- End of inner exception stack trace ---
   at Veldrid.Sdl2.Sdl2Native.SDL_SetHint(String name, String value)
   at Veldrid.Sdl2.Sdl2Window..ctor(String title, Int32 x, Int32 y, Int32 width, Int32 height, SDL_WindowFlags flags, Boolean threadedProcessing)
   at Veldrid.StartupUtilities.VeldridStartup.CreateWindow(WindowCreateInfo& windowCI)
   at Veldrid.StartupUtilities.VeldridStartup.CreateWindow(WindowCreateInfo windowCI)

It's weird because the libsdl2.dylib is there, but it does not seem able to load it. Happens either with x64 or Any CPU.

@GabrielHalvonik
Copy link

When trying to build a create a window in a .NET 6 on a Mac Pro M1 with OS Monterey (12.4) the following exception is thrown.

System.TypeInitializationException: The type initializer for 'Veldrid.Sdl2.Sdl2Native' threw an exception.
 ---> System.IO.FileNotFoundException: Could not find or load the native library from any name: [ libsdl2.dylib ]
   at NativeLibraryLoader.LibraryLoader.LoadNativeLibrary(String[] names, PathResolver pathResolver)
   at NativeLibraryLoader.NativeLibrary..ctor(String[] names, LibraryLoader loader, PathResolver pathResolver)
   at NativeLibraryLoader.NativeLibrary..ctor(String[] names)
   at Veldrid.Sdl2.Sdl2Native.LoadSdl2()
   at Veldrid.Sdl2.Sdl2Native..cctor()
   --- End of inner exception stack trace ---
   at Veldrid.Sdl2.Sdl2Native.SDL_SetHint(String name, String value)
   at Veldrid.Sdl2.Sdl2Window..ctor(String title, Int32 x, Int32 y, Int32 width, Int32 height, SDL_WindowFlags flags, Boolean threadedProcessing)
   at Veldrid.StartupUtilities.VeldridStartup.CreateWindow(WindowCreateInfo& windowCI)
   at Veldrid.StartupUtilities.VeldridStartup.CreateWindow(WindowCreateInfo windowCI)

It's weird because the libsdl2.dylib is there, but it does not seem able to load it. Happens either with x64 or Any CPU.

Did you manage to solve this problem?

@kateusz
Copy link

kateusz commented Mar 23, 2024

working workaround:

brew install sdl2
then add environment variable DYLD_LIBRARY_PATH=/opt/homebrew/lib to .bash_profile or set it inside Run/Debug configuration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants