NSString.FromHandle exception

NSString.FromHandle is crashing the application when trying to create NSString from const char* passed from iOS C method. I'm assuming that NSString.FromHandle is equivalent to

const char* ret = C_someMethod();
[[NSString alloc] initWithUTF8String:ret];

and this works on iOS but

var ptr = C_someMethod();
var str = NSString.FromHandle(ptr);

doesn't works.

This question is related to https://forums.xamarin.com/discussion/40610/binding-const-char-to-method where also NSString.FromHandle took place during conversion to PlainString/string.

Stack trace:

2016-12-30 12:51:15.372 RssReader[1376:468616] critical: Stacktrace:

2016-12-30 12:51:15.372 RssReader[1376:468616] critical:   at <unknown> <0xffffffff>
2016-12-30 12:51:15.373 RssReader[1376:468616] critical:   at (wrapper managed-to-native) ObjCRuntime.Messaging.IntPtr_objc_msgSend (intptr,intptr) <0x00007>
2016-12-30 12:51:15.373 RssReader[1376:468616] critical:   at Foundation.NSString.FromHandle (intptr) [0x00012] in /Users/builder/data/lanes/3985/4d858103/source/xamarin-macios/src/Foundation/NSString.cs:179
2016-12-30 12:51:15.374 RssReader[1376:468616] critical:   at RssReader.Delegates.CustomGDHttpRequestDelegate.OnStatusChange (GoodDynamics.GDHttpRequest) [0x0012f] in /Users/mwesolowski/git/wm_xamarin/iOS/RssReader/Delegates/CustomGDHttpRequestDelegate.cs:86
2016-12-30 12:51:15.375 RssReader[1376:468616] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000f3>
2016-12-30 12:51:15.375 RssReader[1376:468616] critical:   at <unknown> <0xffffffff>
2016-12-30 12:51:15.376 RssReader[1376:468616] critical:   at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <0x00007>
2016-12-30 12:51:15.377 RssReader[1376:468616] critical:   at UIKit.UIApplication.Main (string[],intptr,intptr) [0x00005] in /Users/builder/data/lanes/3985/4d858103/source/xamarin-macios/src/UIKit/UIApplication.cs:79
2016-12-30 12:51:15.377 RssReader[1376:468616] critical:   at UIKit.UIApplication.Main (string[],string,string) [0x00038] in /Users/builder/data/lanes/3985/4d858103/source/xamarin-macios/src/UIKit/UIApplication.cs:63
2016-12-30 12:51:15.378 RssReader[1376:468616] critical:   at RssReader.Application.Main (string[]) [0x00008] in /Users/mwesolowski/git/wm_xamarin/iOS/RssReader/Main.cs:13
2016-12-30 12:51:15.378 RssReader[1376:468616] critical:   at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0x000f3>
2016-12-30 12:51:15.379 RssReader[1376:468616] critical: 
Native stacktrace:

2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    0   RssReader                           0x00000001006e96ac mono_handle_native_sigsegv + 260
2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    1   RssReader                           0x00000001006f4ca8 mono_sigsegv_signal_handler + 336
2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    2   libsystem_platform.dylib            0x0000000187fe9348 _sigtramp + 52
2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    3   RssReader                           0x00000001008ff518 wrapper_managed_to_native_ObjCRuntime_Messaging_IntPtr_objc_msgSend_intptr_intptr + 104
2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    4   RssReader                           0x00000001008bcc48 Foundation_NSString_FromHandle_intptr + 72
2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    5   RssReader                           0x000000010081bcf4 RssReader_Delegates_CustomGDHttpRequestDelegate_OnStatusChange_GoodDynamics_GDHttpRequest + 2340
2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    6   RssReader                           0x0000000100b93044 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 244
2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    7   RssReader                           0x00000001006f7e68 mono_jit_runtime_invoke + 1776
2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    8   RssReader                           0x0000000100770b9c do_runtime_invoke + 112
2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    9   RssReader                           0x0000000100770af8 mono_runtime_invoke + 208
2016-12-30 12:51:15.647 RssReader[1376:468616] critical:    10  RssReader                           0x0000000101480dcc _Z30native_to_managed_trampoline_6P11objc_objectP13objc_selectorPP11_MonoMethodS0_PKcS7_S7_ + 476
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    11  RssReader                           0x0000000101486cc4 -[RssReader_Delegates_CustomGDHttpRequestDelegate onStatusChange:] + 80
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    12  RssReader                           0x0000000100259b64 _ZN20GDHttpRequestAdapter14onStatusChangeEv + 132
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    13  RssReader                           0x0000000100352fec _ZN2GD11HttpRequest13dispatchEventEv + 100
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    14  RssReader                           0x00000001005a6414 _ZN2GT13SchedulerBase19s_scheduledCallbackEPv + 184
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    15  RssReader                           0x0000000100312b80 -[AppleTimer fire] + 92
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    16  Foundation                          0x0000000189a6d048 <redacted> + 340
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    17  CoreFoundation                      0x0000000188f06b5c <redacted> + 24
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    18  CoreFoundation                      0x0000000188f064a4 <redacted> + 524
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    19  CoreFoundation                      0x0000000188f040a4 <redacted> + 804
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    20  CoreFoundation                      0x0000000188e322b8 CFRunLoopRunSpecific + 444
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    21  GraphicsServices                    0x000000018a8e6198 GSEventRunModal + 180
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    22  UIKit                               0x000000018ee797fc <redacted> + 684
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    23  UIKit                               0x000000018ee74534 UIApplicationMain + 208
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    24  RssReader                           0x00000001008fe8e4 wrapper_managed_to_native_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 340
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    25  RssReader                           0x00000001008cd91c UIKit_UIApplication_Main_string___intptr_intptr + 44
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    26  RssReader                           0x00000001008cd8dc UIKit_UIApplication_Main_string___string_string + 172
2016-12-30 12:51:15.648 RssReader[1376:468616] critical:    27  RssReader                           0x0000000100817444 RssReader_Application_Main_string__ + 164
2016-12-30 12:51:15.649 RssReader[1376:468616] critical:    28  RssReader                           0x0000000100b93044 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 244
2016-12-30 12:51:15.649 RssReader[1376:468616] critical:    29  RssReader                           0x00000001006f7e68 mono_jit_runtime_invoke + 1776
2016-12-30 12:51:15.649 RssReader[1376:468616] critical:    30  RssReader                           0x0000000100770b9c do_runtime_invoke + 112
2016-12-30 12:51:15.649 RssReader[1376:468616] critical:    31  RssReader                           0x0000000100773f30 do_exec_main_checked + 152
2016-12-30 12:51:15.649 RssReader[1376:468616] critical:    32  RssReader                           0x00000001006dc994 mono_jit_exec + 260
2016-12-30 12:51:15.649 RssReader[1376:468616] critical:    33  RssReader                           0x0000000100816964 xamarin_main + 2136
2016-12-30 12:51:15.649 RssReader[1376:468616] critical:    34  RssReader                           0x000000010148e5f0 main + 96
2016-12-30 12:51:15.649 RssReader[1376:468616] critical:    35  libdyld.dylib                       0x0000000187e155b8 <redacted> + 4
2016-12-30 12:51:15.649 RssReader[1376:468616] critical: 
Sign In or Register to comment.