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

[release/8.0.1xx-preview4] [tests] Find a workaround for #xamarin/maccore@2668. #18181

Merged
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: 25 additions & 0 deletions tests/common/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;

using ObjCRuntime;
using Foundation;
#if !__MACOS__
using UIKit;
Expand Down Expand Up @@ -48,9 +51,31 @@ public override bool FinishedLaunching (UIApplication application, NSDictionary
public static class MainClass {
static void Main (string [] args)
{
#if __MACCATALYST__
NativeLibrary.SetDllImportResolver (typeof (NSObject).Assembly, DllImportResolver);
NativeLibrary.SetDllImportResolver (typeof (MainClass).Assembly, DllImportResolver);
#endif
#if !__MACOS__
UIApplication.Main (args, null, typeof (AppDelegate));
#endif
}

#if __MACCATALYST__
// This is a workaround for a temporary issue in the .NET runtime
// See https://github.com/xamarin/maccore/issues/2668
// The issue is present in .NET 7.0.5, and will likely be fixed in .NET 7.0.6.
static IntPtr DllImportResolver (string libraryName, global::System.Reflection.Assembly assembly, DllImportSearchPath? searchPath)
{
switch (libraryName) {
case "/System/Library/Frameworks/SceneKit.framework/SceneKit":
case "/System/Library/Frameworks/SceneKit.framework/Versions/A/SceneKit":
var rv = NativeLibrary.Load (libraryName);
Console.WriteLine ($"DllImportResolver callback loaded library \"{libraryName}\" from a P/Invoke in \"{assembly}\" => 0x{rv.ToString ("x")}");
return rv;
default:
return IntPtr.Zero;
}
}
#endif
}
#endif // !__WATCHOS__