2
votes

I am wrapping an Objective-c library in Monotouch. The problem is that, after generating the DLL using btouch, and when I try to use some the classes from the DLL in a sample application, the classHandle of most of the classes return 0x0. I debugged the issue and I discovered that class_ptr, which is used by Messaging class, returns 0x0 as well.

I checked the build output (after building the project in MonoDevelop) and it looks it links my native library but I still get the same error. The build output is included below. The issue is that I have a protocol GDiOSDelegate defined as follows

@protocol GDiOSDelegate
@required

- (void)handleEvent:(GDAppEvent*)anEvent;
@end

This protocol is used by GDiOS class (that I also included) but it also needs to interact with UIApplicationDelegate as HandleEvent method needs to communicate with some objects from UIApplicationDelegate (The equivalent sample code that uses the library, in Objective-C, had a class A : NSObject ).

The way I had it was that in the binding of GDiOSDelegate I set the typeof property to UIApplicationDelegate instead of NSObject

[BaseType(typeof(UIApplicationDelegate))]

So, coming back to the error I was having after I use some methods from the Monotouch binding DLL, it was throwing an exception saying AppDelegate does not implement UIApplicationDelegate.

[Register ("AppDelegate")]
public partial class AppDelegate : GDiOSDelegate
{...}

This happens even if I put UIApplicationDelegate instead of GDiOSDelegate as base class.

The build output:

Building: GDBinding (Debug)

Build started 7/16/2012 9:03:46 AM.
__________________________________________________
Project "/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj" (Build   target(s)):

Target CreateGeneratedSourcesDir:
    Created directory "obj/Debug/ios/"

Target PrepareForBuild:
    Configuration: Debug Platform: AnyCPU

Target CopyFilesMarkedCopyLocal:
    Copying file from '/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll' to '/Users/thabetkacem/Projects/GDBinding/GDBinding/bin/Debug/GDBinding.dll'

Target GenerateSatelliteAssemblies:
No input files were specified for target GenerateSatelliteAssemblies, skipping.

Target GenerateBindings:
    Tool /Developer/MonoTouch/usr/bin/btouch execution started with arguments: /d:DEBUG GDBinding.cs /s:StructsAndEnums.cs /tmpdir:obj/Debug/ios/  /sourceonly:obj/Debug/ios//sources.list 
GDBinding.cs(642,22): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?

Target CoreCompile:
    Tool /Developer/MonoTouch/usr/bin/smcs execution started with arguments: /noconfig /debug:full /debug+ /optimize- /out:obj/Debug/GDBinding.dll /resource:libGD.a libGD.linkwith.cs Extra.cs AssemblyInfo.cs StructsAndEnums.cs obj/Debug/ios/ObjCRuntime/Messaging.g.cs obj/Debug/ios/GDBinding/GDCReadStream.g.cs obj/Debug/ios/GDBinding/GDCWriteStream.g.cs obj/Debug/ios/GDBinding/GDPersistentStoreCoordinator.g.cs obj/Debug/ios/GDBinding/GDFileSystem.g.cs obj/Debug/ios/GDBinding/GDDirectByteBuffer.g.cs obj/Debug/ios/GDBinding/GDSocketDelegate.g.cs obj/Debug/ios/GDBinding/GDSocket.g.cs obj/Debug/ios/GDBinding/GDHttpRequestDelegate.g.cs obj/Debug/ios/GDBinding/GDHttpRequest.g.cs obj/Debug/ios/GDBinding/NSURLCache.g.cs obj/Debug/ios/GDBinding/GDURLLoadingSystem.g.cs obj/Debug/ios/GDBinding/GDCacheController.g.cs obj/Debug/ios/GDBinding/GDPushConnectionDelegate.g.cs obj/Debug/ios/GDBinding/GDPushConnection.g.cs obj/Debug/ios/GDBinding/GDPushChannelDelegate.g.cs obj/Debug/ios/GDBinding/GDPushChannel.g.cs obj/Debug/ios/GDBinding/GDSecureDocs.g.cs obj/Debug/ios/GDBinding/GDAppEvent.g.cs obj/Debug/ios/GDBinding/GDiOSDelegate.g.cs obj/Debug/ios/GDBinding/GDiOS.g.cs obj/Debug/ios/GDBinding/NSMutableURLRequest.g.cs /target:library /unsafe+ /define:DEBUG /reference:/Developer/MonoTouch/usr/lib/mono/2.1/System.dll /reference:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll /reference:../../../Desktop/GDExtended/GDBinding.dll /reference:/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll /reference:/Developer/MonoTouch/usr/lib/mono/2.1/mscorlib.dll /warn:4
obj/Debug/ios/GDBinding/GDSocket.g.cs(273,53): warning CS0436: The type   `GDBinding.GDSocketDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(541,58): warning CS0436: The type `GDBinding.GDHttpRequestDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(180,61): warning CS0436: The type `GDBinding.GDPushConnectionDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition 
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(175,58): warning CS0436: The type `GDBinding.GDPushChannelDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDiOS.g.cs(393,50): warning CS0436: The type `GDBinding.GDiOSDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(53,134): warning CS0436: The type `GDBinding.GDFileStat' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(159,31): warning CS0436: The type `GDBinding.GDCReadStream' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(181,31): warning CS0436: The type `GDBinding.GDCWriteStream' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDDirectByteBuffer.g.cs(139,46): warning CS0108: `GDBinding.GDDirectByteBuffer.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDSocket.g.cs(177,32): warning CS0436: The type `GDBinding.GDDirectByteBuffer' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(377,46): warning CS0108: `GDBinding.GDHttpRequest.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(449,32): warning CS0436: The type `GDBinding.GDHttpRequest_state_t' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/NSURLCache.g.cs(79,57): warning CS0436: The type `GDBinding.NSURLCache' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(84,31): warning CS0436: The type `GDBinding.GDPushConnection' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(148,46): warning CS0108: `GDBinding.GDPushChannel.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDSecureDocs.g.cs(101,85): warning CS0436: The type `GDBinding.SendFileSuccessBlock' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(82,32): warning CS0436: The type `GDBinding.GDAppResultCode' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(102,32): warning CS0436: The type `GDBinding.GDAppEventType' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDiOSDelegate.g.cs(76,51): warning CS0436: The type `GDBinding.GDAppEvent' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDiOS.g.cs(139,36): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?
obj/Debug/ios/GDBinding/GDiOS.g.cs(163,31): warning CS0436: The type `GDBinding.GDiOS' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/GDiOS.g.cs(281,94): warning CS0436: The type `GDBinding.GDUIColorTheme' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/GDBinding/NSMutableURLRequest.g.cs(83,67): warning CS0436: The type `GDBinding.NSMutableURLRequest' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(44,84): warning CS0436: The type `GDBinding.Messaging' conflicts with the imported type of same name'. Ignoring the imported type definition
/Users/thabetkacem/Desktop/GDExtended/GDBinding.dll (Location of the symbol related to previous warning)

Target DeployOutputFiles:
    Copying file from '/Users/thabetkacem/Projects/GDBinding/GDBinding/obj/Debug/GDBinding.dll.mdb' to '/Users/thabetkacem/Projects/GDBinding/GDBinding/bin/Debug/GDBinding.dll.mdb'
    Copying file from '/Users/thabetkacem/Projects/GDBinding/GDBinding/obj/Debug/GDBinding.dll' to '/Users/thabetkacem/Projects/GDBinding/GDBinding/bin/Debug/GDBinding.dll'
Done building project "/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj".

Build succeeded.

Warnings:

/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj (Build) ->    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Xamarin.ObjcBinding.CSharp.targets 
(GenerateBindings target) ->

GDBinding.cs(642,22): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?

/Users/thabetkacem/Projects/GDBinding/GDBinding/GDBinding.csproj (Build) ->
/Library/Frameworks/Mono.framework/Versions/2.10.9/lib/mono/4.0/Microsoft.CSharp.Targets  (CoreCompile target) ->

obj/Debug/ios/GDBinding/GDSocket.g.cs(273,53): warning CS0436: The type `GDBinding.GDSocketDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(541,58): warning CS0436: The type `GDBinding.GDHttpRequestDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(180,61): warning CS0436: The type `GDBinding.GDPushConnectionDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(175,58): warning CS0436: The type `GDBinding.GDPushChannelDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDiOS.g.cs(393,50): warning CS0436: The type `GDBinding.GDiOSDelegate' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(53,134): warning CS0436: The type `GDBinding.GDFileStat' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(159,31): warning CS0436: The type `GDBinding.GDCReadStream' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDFileSystem.g.cs(181,31): warning CS0436: The type `GDBinding.GDCWriteStream' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDDirectByteBuffer.g.cs(139,46): warning CS0108: `GDBinding.GDDirectByteBuffer.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
obj/Debug/ios/GDBinding/GDSocket.g.cs(177,32): warning CS0436: The type `GDBinding.GDDirectByteBuffer' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(377,46): warning CS0108: `GDBinding.GDHttpRequest.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
obj/Debug/ios/GDBinding/GDHttpRequest.g.cs(449,32): warning CS0436: The type `GDBinding.GDHttpRequest_state_t' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/NSURLCache.g.cs(79,57): warning CS0436: The type `GDBinding.NSURLCache' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDPushConnection.g.cs(84,31): warning CS0436: The type `GDBinding.GDPushConnection' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDPushChannel.g.cs(148,46): warning CS0108: `GDBinding.GDPushChannel.Init' hides inherited member `MonoTouch.Foundation.NSObject.Init()'. Use the new keyword if hiding was intended
obj/Debug/ios/GDBinding/GDSecureDocs.g.cs(101,85): warning CS0436: The type `GDBinding.SendFileSuccessBlock' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(82,32): warning CS0436: The type `GDBinding.GDAppResultCode' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDAppEvent.g.cs(102,32): warning CS0436: The type `GDBinding.GDAppEventType' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDiOSDelegate.g.cs(76,51): warning CS0436: The type `GDBinding.GDAppEvent' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDiOS.g.cs(139,36): warning CS0465: Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?
obj/Debug/ios/GDBinding/GDiOS.g.cs(163,31): warning CS0436: The type `GDBinding.GDiOS' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/GDiOS.g.cs(281,94): warning CS0436: The type `GDBinding.GDUIColorTheme' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/GDBinding/NSMutableURLRequest.g.cs(83,67): warning CS0436: The type `GDBinding.NSMutableURLRequest' conflicts with the imported type of same name'. Ignoring the imported type definition
obj/Debug/ios/ObjCRuntime/Messaging.g.cs(44,84): warning CS0436: The type `GDBinding.Messaging' conflicts with the imported type of same name'. Ignoring the imported type definition

 25 Warning(s)
 0 Error(s)

Time Elapsed 00:00:05.0845450

---------------------- Done ----------------------

Build: 0 errors, 25 warnings


Any help would be greatly appreciated.
1
You need to post some code. Include the Objective-C you are trying to bind and what you put for the C# bindings.jonathanpeppers

1 Answers

0
votes

This can occur if you do not link, manually or (better) with [LinkWith] attribute, the native library (that you binded) with your application.

In such case the selectors message won't reach the native code and will return null (which will show handles (instance or class) to be 0x0.

To confirm this look at your Build Output (inside MonoDevelop) and see if your libX.a is being linked to your application.

Also try this on the simulator (i386) and devices (armv6 and/or armv7) since it's possible that your native library architecture is not available (in your .a).