Type initializer for 'Sdl' threw an exception (macOS)

System.TypeInitializationException: The type initializer for ‘Sdl’ threw an exception. —> System.Exception: Failed to load SDL library.
at Sdl.GetNativeLibrary () [0x00117] in :0
at Sdl…cctor () [0x00000] in :0
— End of inner exception stack trace —
at Microsoft.Xna.Framework.GamePlatform.PlatformCreate (Microsoft.Xna.Framework.Game game) [0x00000] in :0
at Microsoft.Xna.Framework.Game…ctor () [0x00213] in :0
at DigitalJigsawPuzzleSteam.Game1…ctor () [0x0000b] in /Users/Findling/Projects/DigitalJigsawPuzzle/DigitalJigsawPuzzle/Game1.cs:21
at DigitalJigsawPuzzleSteam.Program.Main (System.String[] args) [0x00001] in /Users/Findling/Projects/DigitalJigsawPuzzle/DigitalJigsawPuzzle/Main.cs:24

Can anyone give me advice on how to fix this? Trying to port game to macOS and encountered this error. It is failing on my public Game1: Game { } class in Game1.cs.

Is there something about the use of “Game” on macOS I’m not aware of?

What MonoGame version is this? How did you get the template? SDL is a native library that should be included. You get this error because it’s missing.

I downloaded Monogame 3.7 or 3.7.1 when I first started. I tried downgrading to 3.6. It didn’t fix it so I went back up to 3.7.1.

I’m using Xamarin Studio.

I get that SDL is missing. How do I make it not be missing.

Still stuck on this.

I just tried to create a project and was getting this error too. The only way I could get it to work was to use a project that was created on a Windows computer. Maybe it puts the SDL libraries in the correct place.

Any luck with this? I have the exact same exception in the same place. Using Nuget Monogame 3.7.1.189 on VS for Mac.

In case anyone still facing this problem, I got past this exception on macOS by adding these includes into my project .csproj file:

This will reference the native library and copy it to the bin folder after building.

<ItemGroup> <Reference Include="MonoGame.Framework"> <HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll</HintPath> </Reference> </ItemGroup> <ItemGroup> <MonoGameContentReference Include="Content\Content.mgcb" /> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\x86\SDL2.dll"> <Link>x86\SDL2.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\x64\SDL2.dll"> <Link>x64\SDL2.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\x86\soft_oal.dll"> <Link>x86\soft_oal.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\x64\soft_oal.dll"> <Link>x64\soft_oal.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\x86\libSDL2-2.0.so.0"> <Link>x86\libSDL2-2.0.so.0</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\x64\libSDL2-2.0.so.0"> <Link>x64\libSDL2-2.0.so.0</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\x86\libopenal.so.1"> <Link>x86\libopenal.so.1</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\x64\libopenal.so.1"> <Link>x64\libopenal.so.1</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll.config"> <Link>MonoGame.Framework.dll.config</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\libopenal.1.dylib"> <Link>libopenal.1.dylib</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Include="$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\libSDL2-2.0.0.dylib"> <Link>libSDL2-2.0.0.dylib</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> </ItemGroup> <Import Project="..\Shared\Storyboard.Shared.projitems" Label="Shared" Condition="Exists('..\Shared\Storyboard.Shared.projitems')" /> <Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Common.props')" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />

1 Like

I have exactly the same problem, but I found it compiles on macOS 10.13.6 (High Sierra), but produces the error on macOS 10.15.3 (Catalina). I triple-checked all the installed path, and actual paths in source code, and they are all same on two machines. Why is it so and how can I fix it (if possible)? Any help would be appreciated.

I am using:

  • VS 2019 for Mac 8.4.8
  • .NET Core SDK 3.1.101 for template creation
  • MonoGame.Content.Builder 3.7.0.9
  • MonoGame.Framework.DesktopGL.Core 3.8.0.2

What I do to compile:

I created a project in CLI using dotnet core (dotnet new mgdesktopgl -o mygame), opened it on VS 2019 for Mac, and pressed big shinny “Run” button.

Adding my error msg here for more clarity:

Unhandled exception. System.TypeInitializationException: The type initializer for 'Sdl' threw an exception. ---> System.Exception: Failed to load SDL library. at Sdl.GetNativeLibrary() at Sdl..cctor() --- End of inner exception stack trace --- at Microsoft.Xna.Framework.SdlGamePlatform..ctor(Game game) at Microsoft.Xna.Framework.Game..ctor() at mg_launch_test.Game1..ctor() in /Users/myusername/dev/mg-launch-test/Game1.cs:line 12 at mg_launch_test.Program.Main() in /Users/myusername/dev/mg-launch-test/Program.cs:line 10

Attaching installation guide for future reference.