我有一个绑定obj-c对象的类
public unsafe partial class CUSTOMER_INFO : NSObject {
[Export ("signature", ArgumentSemantic.Retain)]
get {
NSData ret;
if (IsDirectBinding) {
ret = Runtime.GetNSObject<NSData> (global::ApiDefinition.Messaging.IntPtr_objc_msgSend (this.Handle, Selector.GetHandle ("signature")));
} else {
ret = Runtime.GetNSObject<NSData> (global::ApiDefinition.Messaging.IntPtr_objc_msgSendSuper (this.SuperHandle, Selector.GetHandle ("signature")));
}
if (!IsNewRefcountEnabled ())
__mt_Signature_var = ret;
return ret;
}
[Export ("setSignature:", ArgumentSemantic.Retain)]
set {
if (value == null)
throw new ArgumentNullException ("value");
if (IsDirectBinding) {
global::ApiDefinition.Messaging.void_objc_msgSend_IntPtr (this.Handle, Selector.GetHandle ("setSignature:"), value.Handle);
} else {
global::ApiDefinition.Messaging.void_objc_msgSendSuper_IntPtr (this.SuperHandle, Selector.GetHandle ("setSignature:"), value.Handle);
}
if (!IsNewRefcountEnabled ())
__mt_Signature_var = value;
}
}
但是当我声明它并将其传递给方法(在ios绑定库中)时,我得到了已知的异常
用户@SushiHangover建议后System.ExecutionEngineException:尝试JIT编译方法 运行时'CUSTOMER_INFO:set_Signature(Foundation.NSData)' 只有--aot - 。有关详细信息,请参阅http://docs.xamarin.com/ios/about/limitations。
更新 在我生成的代码中的iOS绑定库项目中,我尝试了这种解决方法:
[Register("CUSTOMER_INFO", true)]
//public unsafe partial class CUSTOMER_INFO : NSObject {
public unsafe partial class CUSTOMER_INFO_GENERIC<T> : NSObject where T : NSObject
{
[CompilerGenerated]
static readonly IntPtr class_ptr = Class.GetHandle ("CUSTOMER_INFO");
public override IntPtr ClassHandle { get { return class_ptr; } }
[CompilerGenerated]
[EditorBrowsable (EditorBrowsableState.Advanced)]
[Export ("init")]
public CUSTOMER_INFO_GENERIC () : base (NSObjectFlag.Empty)
{
IsDirectBinding = GetType ().Assembly == global::ApiDefinition.Messaging.this_assembly;
if (IsDirectBinding) {
InitializeHandle (global::ApiDefinition.Messaging.IntPtr_objc_msgSend (this.Handle, global::ObjCRuntime.Selector.GetHandle ("init")), "init");
} else {
InitializeHandle (global::ApiDefinition.Messaging.IntPtr_objc_msgSendSuper (this.SuperHandle, global::ObjCRuntime.Selector.GetHandle ("init")), "init");
}
}
[CompilerGenerated]
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected CUSTOMER_INFO_GENERIC(NSObjectFlag t) : base (t)
{
IsDirectBinding = GetType ().Assembly == global::ApiDefinition.Messaging.this_assembly;
}
[CompilerGenerated]
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected internal CUSTOMER_INFO_GENERIC(IntPtr handle) : base (handle)
{
IsDirectBinding = GetType ().Assembly == global::ApiDefinition.Messaging.this_assembly;
}
// other methods....
// .................
[CompilerGenerated]
object __mt_Signature_var;
[CompilerGenerated]
public virtual NSData SignatureNoJit {
[Export ("signature", ArgumentSemantic.Retain)]
get {
NSData ret;
if (IsDirectBinding) {
ret = Runtime.GetNSObject<NSData> (global::ApiDefinition.Messaging.IntPtr_objc_msgSend (this.Handle, Selector.GetHandle ("signature")));
} else {
ret = Runtime.GetNSObject<NSData> (global::ApiDefinition.Messaging.IntPtr_objc_msgSendSuper (this.SuperHandle, Selector.GetHandle ("signature")));
}
if (!IsNewRefcountEnabled ())
__mt_Signature_var = ret;
return ret;
}
[Export ("setSignature:", ArgumentSemantic.Retain)]
set {
if (value == null)
throw new ArgumentNullException ("value");
if (IsDirectBinding) {
global::ApiDefinition.Messaging.void_objc_msgSend_IntPtr (this.Handle, Selector.GetHandle ("setSignature:"), value.Handle);
} else {
global::ApiDefinition.Messaging.void_objc_msgSendSuper_IntPtr (this.SuperHandle, Selector.GetHandle ("setSignature:"), value.Handle);
}
if (!IsNewRefcountEnabled ())
__mt_Signature_var = value;
}
}
[CompilerGenerated]
protected override void Dispose (bool disposing)
{
base.Dispose (disposing);
if (Handle == IntPtr.Zero) {
__mt_Signature_var = null;
}
}
}
public class CUSTOMER_INFO_NOJIT : CUSTOMER_INFO_GENERIC<NSData>
{
// A specialized subclass and this is passed to your ObjC-based method
}
但是当我打电话时
NSData tmp = NSData.FromArray(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF });
CUSTOMER_INFO_NOJIT CustomerInfo = new CUSTOMER_INFO_NOJIT();
CustomerInfo.CardHolderEmail = CardHolderEMail;
CustomerInfo.CardHolderMobile = CardHolderMobilePhone;
CustomerInfo.SignatureNoJit = tmp;
我再次得到这个例外:
System.ExecutionEngineException:尝试JIT编译方法 “CUSTOMER_INFO_GENERIC`1:set_SignatureNoJit (Foundation.NSData)'在使用--aot-only运行时。看到 http://docs.xamarin.com/ios/about/limitations了解更多信息。
任何人都可以建议我一个解决方法/模式来避免这种异常? 谢谢!
Lewix
答案 0 :(得分:0)
(我可能需要更多的咖啡......所以拿一粒盐......: - )
此:
public unsafe partial class CUSTOMER_INFO : NSObject {
~~~~
}
变为:
public unsafe partial class CUSTOMER_INFO_GENERIC<T> : NSObject where T : NSObject {
~~~~
}
class CUSTOMER_INFO : CUSTOMER_INFO_GENERIC<NSData>
{
// A specialized subclass and this is passed to your ObjC-based method
}
因此this
和set
返回中的get
可以解析为NSData
与NSObject
,并且不需要jitting并且编译器已创建/解决了这些课程......