Mono-nx Switch: Difference between revisions
More actions
No edit summary |
No edit summary |
||
| (One intermediate revision by one other user not shown) | |||
| Line 4: | Line 4: | ||
|description=An unofficial port of the mono runtime as a switch homebrew. | |description=An unofficial port of the mono runtime as a switch homebrew. | ||
|author=exelix11 | |author=exelix11 | ||
|lastupdated= | |lastupdated=2026/07/03 | ||
|type=Developments | |type=Developments | ||
|version= | |version=1 | ||
|license=MIT | |license=MIT | ||
|download=https://github.com/exelix11/mono-nx/releases | |download=https://github.com/exelix11/mono-nx/releases | ||
| Line 22: | Line 22: | ||
This is an unofficial port of the mono runtime to the Switch homebrew toolchain. It can run dotnet 9.0 applications using the mono interpreter by loading the dll or exe files directly on console. It can also build .NET assemblies as static libraries using mono AOT. | This is an unofficial port of the mono runtime to the Switch homebrew toolchain. It can run dotnet 9.0 applications using the mono interpreter by loading the dll or exe files directly on console. It can also build .NET assemblies as static libraries using mono AOT. | ||
The mono-interpreter.zip release contains the mono interpreter, all the dotnet runtime libraries and the file .dll/.exe file association for hbmenu allowing you to copy .net dll programs to your Switch folder and running them directly. To build and use mono-nx, please follow the detailed step-by-step instructions provided in the [https://github.com/exelix11/mono-nx GitHub repository]. | |||
'''What works:''' | '''What works:''' | ||
* Common BCL classes such | * Common BCL classes such as <code>List</code>, <code>StringBuilder</code> and so on. | ||
* P/Invoke, but only with libraries that were statically linked beforehand. | * P/Invoke, but only with libraries that were statically linked beforehand. | ||
* Threads and async. | * Threads and async. | ||
* Most of filesystem APIs. | * Most of filesystem APIs. | ||
* Sockets and http-only support | * Sockets and http-only support for <code>HttpClient</code>. | ||
* .NET wrappers for SDL2 | * .NET wrappers for SDL2 and [https://github.com/ocornut/imgui dear imgui] which are included as static libraries. | ||
* The interpreter seems rather stable even when running more complex programs, I did not test the AOT builds as much. | * The interpreter seems rather stable even when running more complex programs, I did not test the AOT builds as much. | ||
* Unit tests with XHarness (some dotnet repo tests are even passing!). | |||
'''What does not work:''' | '''What does not work:''' | ||
* HTTPS and most | * HTTPS and most of <code>System.Security</code> doesn't work because we have no openssl port on Switch. | ||
* Arbitrary P/Invoke doesn't work due to the lack of dynamic linking, all native function entrypoints must be defined beforehand and statically linked. | * Arbitrary P/Invoke doesn't work due to the lack of dynamic linking, all native function entrypoints must be defined beforehand and statically linked. | ||
* Any other OS-dependant API that was not mentioned previously will likely not work because it was not explicitly implemented. Examples | * Any other OS-dependant API that was not mentioned previously will likely not work because it was not explicitly implemented. Examples are <code>Console.Read</code>, <code>Console.Clear</code>, <code>Process</code>, <code>WinForms</code> and many more. | ||
* Also, exiting the interpreter and launching another dll or sometimes homebrew in the same hbmenu session will eventually crash. | * Also, exiting the interpreter and launching another dll or sometimes homebrew in the same hbmenu session will eventually crash. I'm not sure why this happens, historically mono has had problems [https://github.com/mono/mono/issues/20191 cleaning up resources] but it could also be an issue related to the homebrew environment. I tried to do [https://github.com/exelix11/mono-nx/blob/master/notes/writeup.md#the-smoke-test some debugging] but ultimately my workaround is to just terminate the process on exit. | ||
'''Included demos:''' | '''Included demos:''' | ||
| Line 49: | Line 50: | ||
==Changelog== | ==Changelog== | ||
'''v1''' | |||
* This build fixes various stability issues, including one related to thread local storage that would crash mono at random. | |||
* I'm also providing an "sdk build" of the toolchain, that is, the final binaries, header files and static libraries needed to build the interpreter without having to build the whole dotnet runtime on your own. To use the sdk zip extract it in the root of the repo, it contains all the correct paths where all the icu and mono artifacts should be. At this point you should be able to build <code>native/interpreter</code> or <code>native/aot</code> directly. I don't expect this setup to survive libnx/gcc/portlibs updates via dkp-pacman so only use it with the monobuild docker container at the commit of this release, as of writing it is based on <code>devkitpro/devkita64:20260219</code>. | |||
'''v0''' | '''v0''' | ||
* First Release. | * First Release. | ||
== External links == | == External links == | ||
* GitHub - https://github.com/exelix11/mono-nx | |||
* GBAtemp - https://www.reddit.com/r/dotnet/comments/1ks83mq/i_ported_the_mono_runtime_as_a_switch_homebrew/ | * GBAtemp - https://www.reddit.com/r/dotnet/comments/1ks83mq/i_ported_the_mono_runtime_as_a_switch_homebrew/ | ||
Latest revision as of 03:30, 10 July 2026
| mono-nx | |
|---|---|
| General | |
| Author | exelix11 |
| Type | Developments |
| Version | 1 |
| License | MIT License |
| Last Updated | 2026/07/03 |
| Links | |
| Download | |
| Website | |
| Source | |
This is an unofficial port of the mono runtime to the Switch homebrew toolchain. It can run dotnet 9.0 applications using the mono interpreter by loading the dll or exe files directly on console. It can also build .NET assemblies as static libraries using mono AOT.
The mono-interpreter.zip release contains the mono interpreter, all the dotnet runtime libraries and the file .dll/.exe file association for hbmenu allowing you to copy .net dll programs to your Switch folder and running them directly. To build and use mono-nx, please follow the detailed step-by-step instructions provided in the GitHub repository.
What works:
- Common BCL classes such as
List,StringBuilderand so on. - P/Invoke, but only with libraries that were statically linked beforehand.
- Threads and async.
- Most of filesystem APIs.
- Sockets and http-only support for
HttpClient. - .NET wrappers for SDL2 and dear imgui which are included as static libraries.
- The interpreter seems rather stable even when running more complex programs, I did not test the AOT builds as much.
- Unit tests with XHarness (some dotnet repo tests are even passing!).
What does not work:
- HTTPS and most of
System.Securitydoesn't work because we have no openssl port on Switch. - Arbitrary P/Invoke doesn't work due to the lack of dynamic linking, all native function entrypoints must be defined beforehand and statically linked.
- Any other OS-dependant API that was not mentioned previously will likely not work because it was not explicitly implemented. Examples are
Console.Read,Console.Clear,Process,WinFormsand many more. - Also, exiting the interpreter and launching another dll or sometimes homebrew in the same hbmenu session will eventually crash. I'm not sure why this happens, historically mono has had problems cleaning up resources but it could also be an issue related to the homebrew environment. I tried to do some debugging but ultimately my workaround is to just terminate the process on exit.
Included demos:
- aot_example.nro is a fully self-contained AOT-complied C# application. It generates a random number and asks you to guess it.
- (*) pad_input.dll is a C# program that reads the controls with the native libnx api.
- (*) example.dll is a C# program that shows most of the APIs that are currently implemented.
- (*) explorer_demo.dll is a C# program that shows a file explorer-like GUI using imgui and SDL2. This will also work on windows and linux with no code changes if you use the author's cimgui fork.
- (*) guess_number.exe is the source from aot_example built with plain csc.exe on a windows vm to show off loading exe files as well. I'm not aware of any way to build this on linux so there's no build script for it.
(*) These will add the dll and exe file association to the hbmenu allowing you to launch them directly.
Changelog
v1
- This build fixes various stability issues, including one related to thread local storage that would crash mono at random.
- I'm also providing an "sdk build" of the toolchain, that is, the final binaries, header files and static libraries needed to build the interpreter without having to build the whole dotnet runtime on your own. To use the sdk zip extract it in the root of the repo, it contains all the correct paths where all the icu and mono artifacts should be. At this point you should be able to build
native/interpreterornative/aotdirectly. I don't expect this setup to survive libnx/gcc/portlibs updates via dkp-pacman so only use it with the monobuild docker container at the commit of this release, as of writing it is based ondevkitpro/devkita64:20260219.
v0
- First Release.