我在Monotouch中包裝Objective-c庫。問題是,在使用btouch生成DLL之後,以及當我嘗試在示例應用程序中使用DLL中的某些類時,大多數類的類都會返回0x0。我調試了這個問題,並且我發現class_ptr(由Messaging類使用)也返回0x0。包裝Monotouch類的ClassHandle返回null
我檢查了構建輸出(在MonoDevelop中構建項目之後),它看起來鏈接了我的本機庫,但仍然出現相同的錯誤。構建輸出包含在下面。問題是,我有定義爲一個協議GDiOSDelegate如下
@protocol GDiOSDelegate
@required
- (void)handleEvent:(GDAppEvent*)anEvent;
@end
此協議通過GDiOS類使用(即我也包括在內),但它也需要作爲handleEvent方法需要與從一些物體進行通信與UIApplicationDelegate交互UIApplicationDelegate(在Objective-C中使用庫的等效示例代碼有一個類A:NSObject)。
我這是在GDiOSDelegate結合我設置的typeof屬性UIApplicationDelegate而不是NSObject的
[BaseType(typeof(UIApplicationDelegate))]
所以,回來我是有錯誤後,我使用了一些方法的方式Monotouch綁定DLL,它拋出一個異常說AppDelegate沒有實現UIApplicationDelegate。
[Register ("AppDelegate")]
public partial class AppDelegate : GDiOSDelegate
{...}
即使我將UIApplicationDelegate而不是GDiOSDelegate作爲基類,也會發生這種情況。
生成的輸出:
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.
您需要張貼一些代碼。包括你試圖綁定的Objective-C以及你爲C#綁定所做的貢獻。 – jonathanpeppers 2012-07-13 12:33:59