Exception System.InvalidCastException when calling a method bound with btouch that returns an object. MonoTouch bug?

走远了吗. 提交于 2019-12-06 16:40:11

I have managed to work around this issue and it does indeed seem to be a bug in MonoTouch. My workaround was to call btouch with the outdir parameter set and then include the generated C# files in my project. So, instead of doing this:

btouch ultralite.cs enum.cs

I did:

btouch ultralite.cs enum.cs -outdir=.

This generated files in two folders ObjCRuntime and Ultralite (the name of my namespace). I removed the ultralite.dll from the references of my project, and instead copied and included the files from these two directories that btouch generated. With the C# files included instead of the dll as reference, the OpenConnection method that I referred to in my question executed correctly and returned the connection object.

I never made any changes to my Objective-C wrapper library, nor the API definition file, so it definitely seems to be a bug in btouch. Or maybe I was missing some other required argument in my original call to btouch. Maybe someone from MonoTouch could shed some light on this.

But, bottom line, my library is finally imported and working correctly in MonoTouch. :) I hope that this information is helpful to anyone else who encounters this problem.

I think the problem is that the native UltraliteConnection object is being initialized with a specific method - initWithULConnection:.

Since this is the case, you have to implement a constructor in your API definition of the UltraliteConnection object:

[Export ("initWithULConnection:")]  
IntPtr Constructor (ULConnection connbase);

And of course, you will also need to bind the ULConnection object for this to work.

It doesn't matter that you have the evaluation version of MonoTouch, it is the same as the commercial, you just can't deploy to devices and the App Store with it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!