Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Realm/Realm/Native/NativeCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
using System.Threading;
using Realms.Helpers;
using Realms.Logging;
#if !NET5_0_OR_GREATER
#if NET5_0_OR_GREATER
using System.Reflection;
#else
using System.IO;
#endif

Expand All @@ -50,7 +52,26 @@ internal static void Initialize()
{
if (libraryName == InteropConfig.DLL_NAME)
{
libraryName = "@rpath/realm-wrappers.framework/realm-wrappers";
var rpath = "@rpath";

var runtimeVersion = Environment.Version;
if (runtimeVersion.Major >= 10)
{
// .NET 10 breaking change: Realm can't use @rpath for runtime library location.
// Solution: Use NSBundle.MainBundle.PrivateFrameworksPath
// Currently it is evaluated through reflection, but could be replaced when platform code evaluation/injection improves in future versions.
var nsBundleType = Assembly.Load("Microsoft.iOS").GetType("Foundation.NSBundle");
var mainBundleProperty = nsBundleType?.GetProperty("MainBundle", BindingFlags.Public | BindingFlags.Static);
var mainBundle = mainBundleProperty?.GetValue(null);
var privateFrameworksPathProperty = nsBundleType?.GetProperty("PrivateFrameworksPath", BindingFlags.Public | BindingFlags.Instance);

if (privateFrameworksPathProperty?.GetValue(mainBundle) is string privateFrameworksPath)
{
rpath = privateFrameworksPath;
}
}

libraryName = $"{rpath}/realm-wrappers.framework/realm-wrappers";
}

return NativeLibrary.Load(libraryName, assembly, searchPath);
Expand Down
Loading