Using ObjCRuntime from custom .NET runtime host (or outside a Xamarin app bundle in general)
- Dominant language
- C#
- Stars
- 2.9k
- Forks
- 576
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 123
Description
I am attempting to use the ObjCRuntime from a custom .NET runtime host on macOS, specifically targeting `net8.0-macos` (same issue for net7 as well). However, I encounter the following exception when executing a DLL directly:
```
Unhandled exception. System.DllNotFoundException: Unable to load shared library '__Internal' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable:
dlopen(/Users/marc-aurel/Documents/repos/Aetherium/Aetherium/bin/Debug/net8.0-macos/osx-arm64/__Internal.dylib, 0x0001): tried: '/Users/marc-aurel/Documents/repos/Aetherium/Aetherium/bin/Debug/net8.0-macos/osx-arm64/__Internal.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/marc-aurel/Documents/repos/Aetherium/Aetherium/bin/Debug/net8.0-macos/osx-arm64/__Internal.dylib' (no such file), '/Users/marc-aurel/Documents/repos/Aetherium/Aetherium/bin/Debug/net8.0-macos/osx-arm64/__Internal.dylib' (no such file)
...
```
The error message suggests that the `__Internal` library or its dependencies cannot be loaded. I understand that currently, the only way to run the application is through the executable in the generated app bundle which provides these exported functions.
For my use case it would be helpful if the initialization process performed by the Xamarin wrapper could be replicated in a custom .NET runtime host, or even better all necessary bindings moved to a native portable dylib. This would enable the use of ObjCRuntime and other Xamarin bindings outside of the generated app bundle.
There seems to be a similar issue here https://github.com/ForNeVeR/AvaloniaRider/issues/237#issuecomment-1323452178.
### Steps to Reproduce
1. Create a new macOS project using the command `dotnet new macos`.
2. Build the project using the command `dotnet build`.
3. Run the generated DLL directly using the command `dotnet MyApp.dll`.
### Expected Behavior
Runs the application.
### Actual Behavior
Exception described above.
### Environment
Version information
```
Visual Studio Community 2022 for Mac
Version 17.5.6 (build 3)
Installation UUID: af06fdaa-a9cd-45fc-8889-e9912615f626
Runtime
.NET 7.0.1 (64-bit)
Architecture: Arm64
Microsoft.macOS.Sdk 12.3.2372; git-rev-head:754abbf6a3563f6267e5717ae832b4ac25b1f2fb; git-branch:release/7.0.1xx-xcode13.3
Roslyn (Language Service)
4.5.0-3.23056.2+97881342e427ff5cdcba8f12b12ff8e6f3564431
NuGet
Version: 6.4.0.117
.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/7.0.302/Sdks
SDK Versions:
8.0.100-preview.4.23260.5
8.0.100-preview.1.23115.2
8.0.100-preview.1.23109.10
7.0.302
6.0.408
MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks
.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
8.0.0-preview.4.23259.5
8.0.0-preview.1.23110.8
8.0.0-preview.1.23106.5
7.0.5
6.0.16
Xamarin Designer
Version: 17.5.3.47
Hash: e8b5d371c3
Branch: remotes/origin/d17-5
Build date: 2023-05-18 17:57:49 UTC
Xamarin.Profiler
Version: 1.8.0.49
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler
Updater
Version: 11
Xamarin.Android
Not Installed
Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.16.1
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Eclipse Temurin JDK
Java SDK: Not Found
Android SDK Manager
Version: 17.5.0.33
Hash: f0c0c52
Branch: remotes/origin/d17-5~2
Build date: 2023-05-18 17:57:54 UTC
Android Device Manager
Version: 0.0.0.1245
Hash: 7f8a990
Branch: 7f8a990
Build date: 2023-05-18 17:57:55 UTC
Apple Developer Tools
Xcode: 14.3.1 21815
Build: 14E300c
Xamarin.Mac
Version: 9.1.0.5 Visual Studio Community
Hash: 7738c90c9
Branch: xcode14.2
Build date: 2023-01-25 15:56:14-0500
Xamarin.iOS
Not Installed
Build Information
Release ID: 1705060003
Git revision: 6472fea49fa01feff06feefde4e358c02df42934
Build date: 2023-05-18 17:56:09+00
Build branch: release-17.5
Build lane: release-17.5
Operating System
Mac OS X 13.4.0
Darwin 22.5.0 Darwin Kernel Version 22.5.0
Mon Apr 24 20:53:19 PDT 2023
root:xnu-8796.121.2~5/RELEASE_ARM64_T6020 arm64
```
### Build Logs
N/A
### Example Project (If Possible)
Described in steps to reproduce
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.