0

Can anyone help me?

I'm developing a Xamarin Forms app in Visual Studio 2022 on a Windows PC. I have VS attached to a MacinCloud Mac and an iPhone connected to the Windows PC.

My app deploys and starts up on the iPhone but when I go to login it crashes.

The line of code it is crashing on is making a call to HttpClient.PostAsync to call back to our API to authenticate.

The error and crash dump are below.

Any ideas?

Thanks,

Paul.

Foundation.MonoTouchException
  Message=Objective-C exception thrown.  Name: NSMallocException Reason: Failed to grow buffer

Native stack trace:
    0   CoreFoundation                      0x0000000180a35060 B2D21CFD-378C-36D5-BAF7-3F70599CFEFC + 626784
    1   libobjc.A.dylib                     0x00000001990a9f54 objc_exception_throw + 60
    2   CoreFoundation                      0x0000000180b42af0 B2D21CFD-378C-36D5-BAF7-3F70599CFEFC + 1731312
    3   CoreFoundation                      0x0000000180b3addc B2D21CFD-378C-36D5-BAF7-3F70599CFEFC + 1699292
    4   CoreFoundation                      0x00000001809cf28c __CFSafelyReallocate + 72
    5   Foundation                          0x00000001821f6a48 D59C6975-5AF2-37BC-93BE-43B80B4293A5 + 232008
    6   Foundation                          0x00000001821f26d4 D59C6975-5AF2-37BC-93BE-43B80B4293A5 + 214740
    7   Xamarin.PreBuilt.iOS                0x00000001024e9c54 do_icall + 328
    8   Xamarin.PreBuilt.iOS                0x00000001024e82e4 do_icall_wrapper + 296
    9   Xamarin.PreBuilt.iOS                0x00000001024df1d8 interp_exec_method_full + 2740
    10  Xamarin.PreBuilt.iOS                0x00000001024dd768 interp_runtime_invoke + 336
    11  Xamarin.PreBuilt.iOS                0x000000010234ae70 mono_jit_runtime_invoke + 900
    12  Xamarin.PreBuilt.iOS                0x00000001023f9188 mono_runtime_try_invoke + 156
    13  Xamarin.PreBuilt.iOS                0x00000001023faddc mono_runtime_invoke + 100
    14  Xamarin.PreBuilt.iOS                0x00000001022613e0 _ZL31native_to_managed_trampoline_11P11objc_objectP13objc_selectorPP11_MonoMethodj + 244
    15  Xamarin.PreBuilt.iOS                0x00000001022a7db8 -[UIKit_UIControlEventProxy BridgeSelector] + 44
    16  UIKitCore                           0x000000018330abf0 8388EB03-002B-3B35-A78A-6A022894292E + 5016560
    17  UIKitCore                           0x0000000183436a4c 8388EB03-002B-3B35-A78A-6A022894292E + 6244940
    18  UIKitCore                           0x00000001831b22c8 8388EB03-002B-3B35-A78A-6A022894292E + 3605192
    19  UIKitCore                           0x000000018324eae0 8388EB03-002B-3B35-A78A-6A022894292E + 4246240
    20  UIKitCore                           0x00000001834e17c0 8388EB03-002B-3B35-A78A-6A022894292E + 6944704
    21  UIKitCore                           0x0000000182fa6d40 8388EB03-002B-3B35-A78A-6A022894292E + 1461568
    22  UIKitCore                           0x0000000182fd98c8 8388EB03-002B-3B35-A78A-6A022894292E + 1669320
    23  UIKitCore                           0x0000000182fe6a68 8388EB03-002B-3B35-A78A-6A022894292E + 1722984
    24  UIKitCore                           0x0000000183196318 8388EB03-002B-3B35-A78A-6A022894292E + 3490584
    25  UIKitCore                           0x0000000182fb9c30 8388EB03-002B-3B35-A78A-6A022894292E + 1539120
    26  UIKitCore                           0x0000000182faea1c 8388EB03-002B-3B35-A78A-6A022894292E + 1493532
    27  UIKitCore                           0x0000000182fb3ec8 8388EB03-002B-3B35-A78A-6A022894292E + 1515208
    28  CoreFoundation                      0x0000000180a57020 B2D21CFD-378C-36D5-BAF7-3F70599CFEFC + 765984
    29  CoreFoundation                      0x0000000180a67ce0 B2D21CFD-378C-36D5-BAF7-3F70599CFEFC + 834784
    30  CoreFoundation                      0x00000001809a1fe8 B2D21CFD-378C-36D5-BAF7-3F70599CFEFC + 24552
    31  CoreFoundation                      0x00000001809a77f4 B2D21CFD-378C-36D5-BAF7-3F70599CFEFC + 47092
    32  CoreFoundation                      0x00000001809bb3b8 CFRunLoopRunSpecific + 600
    33  GraphicsServices                    0x000000019c34b38c GSEventRunModal + 164
    34  UIKitCore                           0x000000018335b6a8 8388EB03-002B-3B35-A78A-6A022894292E + 5346984
    35  UIKitCore                           0x00000001830da7f4 UIApplicationMain + 2092
    36  Xamarin.PreBuilt.iOS                0x00000001024e9bb0 do_icall + 164
    37  Xamarin.PreBuilt.iOS                0x00000001024e82e4 do_icall_wrapper + 296
    38  Xamarin.PreBuilt.iOS                0x00000001024df1d8 interp_exec_method_full + 2740
    39  Xamarin.PreBuilt.iOS                0x00000001024dd768 interp_runtime_invoke + 336
    40  Xamarin.PreBuilt.iOS                0x000000010234ae70 mono_jit_runtime_invoke + 900
    41  Xamarin.PreBuilt.iOS                0x00000001023f7984 mono_runtime_invoke_checked + 148
    42  Xamarin.PreBuilt.iOS                0x00000001023fe000 mono_runtime_try_invoke_array + 1272
    43  Xamarin.PreBuilt.iOS                0x00000001023a74f0 ves_icall_InternalInvoke + 1036
    44  Xamarin.PreBuilt.iOS                0x00000001023b7780 ves_icall_InternalInvoke_raw + 108
    45  Xamarin.PreBuilt.iOS                0x00000001024e9bb0 do_icall + 164
    46  Xamarin.PreBuilt.iOS                0x00000001024e82e4 do_icall_wrapper + 296
    47  Xamarin.PreBuilt.iOS                0x00000001024df1d8 interp_exec_method_full + 2740
    48  Xamarin.PreBuilt.iOS                0x00000001024dd768 interp_runtime_invoke + 336
    49  Xamarin.PreBuilt.iOS                0x000000010234ae70 mono_jit_runtime_invoke + 900
    50  Xamarin.PreBuilt.iOS                0x00000001023f7984 mono_runtime_invoke_checked + 148
    51  Xamarin.PreBuilt.iOS                0x00000001023fcbf8 mono_runtime_exec_main_checked + 128
    52  Xamarin.PreBuilt.iOS                0x000000010232f850 mono_jit_exec + 376
    53  Xamarin.PreBuilt.iOS                0x00000001024db834 xamarin_main + 1944
    54  Xamarin.PreBuilt.iOS                0x00000001022f74f4 main + 76
    55  dyld                                0x0000000102e71a24 start + 520

  Source=Xamarin.iOS
  StackTrace:
  at ObjCRuntime.Runtime.ThrowNSException (System.IntPtr ns_exception) [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:449 
  at ObjCRuntime.Runtime.throw_ns_exception (System.IntPtr exc) [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/runtime/Delegates.generated.cs:392 
  at (wrapper native-to-managed) ObjCRuntime.Runtime.throw_ns_exception(intptr)
  • Does your device have an access to your API? – Dmitry Grebennikov Feb 11 '22 at 12:14
  • Yeah, sorry I meant to say it works fine in the simulator but just crashes on a real device. – Paul Lonsdale Feb 11 '22 at 12:22
  • do you have any exception handling or logging in your app? Is your API reachable from the device? Why haven't you posted any relevant code? – Jason Feb 11 '22 at 12:24
  • @PaulLonsdale yes I understand that. That's why I asked you about your API. Is it inside your network or it available only on your developer machine or it public? Physical device can't use your workstation network resources. That's why you need to be sure that your physical device have an access to your API. – Dmitry Grebennikov Feb 11 '22 at 12:39
  • Hi Jason, the crash doesn't get caught in a try/catch, it just crashes with the above error. – Paul Lonsdale Feb 11 '22 at 16:15
  • Dimitry, how would I test if my device has access to my API? I will check the URL as it may well be trying to access a local API as it's in debug mode. Thank you, I'll try looking at that. – Paul Lonsdale Feb 11 '22 at 16:16
  • What is "HttpClient implementation" setting in "iOS Build" set to? Did you try this [solution](https://stackoverflow.com/questions/70064427/xamarin-forms-httpclient-postasync-always-throw-nsmallocexception) – Trevor Balcom Feb 11 '22 at 20:26

1 Answers1

0

I have managed to solve this issue by creating a handler and passing it in to the constructor of my Http client.

var handler = new HttpClientHandler();
var httpClient = new HttpClient(handler);

I thought I had already tried this solution earlier to no avail but I found a second place that was creating the client and implementing it there as well solved the issue.