c# - 调用 method_getImplementation 在设备上抛出 ExecutionEngineException

标签 c# ios xamarin.ios xamarin

我正在尝试根据问题 here 的答案实现调配.我在 github 上有一个例子.完整的崩溃是 here .

[DllImport("/usr/lib/libobjc.dylib")]
extern static Func<IntPtr,IntPtr,IntPtr> method_getImplementation(IntPtr method);

delegate void CaptureDelegate(IntPtr block,IntPtr self,IntPtr uiView);

[MonoPInvokeCallback(typeof(CaptureDelegate))]
static void MyCapture(IntPtr block, IntPtr self, IntPtr uiView)
{
}

static void HijackWillMoveToSuperView()
{
    var method = class_getInstanceMethod(new UIView().ClassHandle, new Selector("willMoveToSuperview:").Handle);

    original_impl = method_getImplementation(method);

    var block_value = new BlockLiteral();
    CaptureDelegate d = MyCapture;
    block_value.SetupBlock(d, null);
    var imp = imp_implementationWithBlock(ref block_value);
    method_setImplementation(method, imp);
}

该示例适用于模拟器,但不适用于设备。在设备上,

 original_impl = method_getImplementation(method);

抛出一个ExecutionEngineException

Attempting to JIT compile method '(wrapper managed-to-native) System.Func`3:wrapper_aot_native (intptr&,intptr,intptr)' while running with --aot-only.

我需要做什么才能进行 AOT 编译?或者,这是在 ARM64 上调用 method_getImplementation(method) 的问题吗?我找到了一些相关信息 here .

It seems like using an imp_implementationWithBlock crashes on arm64.

还有更多here :

Note the cast to objc_msgSend. While this (by luck) worked without casting in the earlier days, this will probably crash your arm64 build if you don’t cast this correctly, because the variable argument casting specifications changed.

在 objective-c 中有一个例子 here ,其中检查了体系结构并且 32 和 64 的行为不同。我想知道我是否有同样的问题。

最佳答案

返回值是一个“IntPtr”,而不是一个“Func”。

关于c# - 调用 method_getImplementation 在设备上抛出 ExecutionEngineException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28550076/

相关文章:

c# - 将对象放置在预扫描房间的设定位置

c# - 将相当于关联数组的内容从 Controller 传递到 MVC 4 中的 View 的最佳方法

ios - NSNotification 被 UITabBarController 多次调用

ios - 类型 'UIButton' 的值没有成员 'reactive'

ios - 删除 'Old' 恢复购买交易

xamarin - 加载失败 : Name cannot begin with the '<' character, 十六进制值 0*3c。 610 路,位置 3

ios - 如何从 Xamarin.ios 中的库中选择图像

C# 连接字符串或字符数组

xamarin.ios - 为 Monotouch-dialog 元素设置自定义字体

c# - Entity Framework (6.1.3) 更新未反射(reflect)在 DataContext 中