Crash in mono on HttpClient().PostAsync

LoganMcKinleyLoganMcKinley USUniversity ✭✭

I need to post data to a webservice from my xamarin.forms application. I get a mono crash on my ipod touch when client.PostAsync is called. I don't (know how to?) get any usable crash data. One thing I notice is that even though it is an awaited async call, it does not appear to wait for a response (the response object is null) before moving on. It then crashes in the next couple of seconds. It looks like it might be that it crashes when it gets a response and tries to resume the thread.

It never hits any breakpoints, it just hard stops. I have included an example call, the post data doesn't seem to make a difference. I get the same response when I post an empty stringcontent.

I don't get the same crash in the emulator, only when it is deployed to a device. Right now and for the foreseeable future this app will only be used on an ipod, so I am happy to move the post from xamarin.forms and into the ios code if that would be preferable/more stable.

public static async Task<bool> UpdateContact(App app, string oldContactName)
        {
            try
            {
                var c = new
                {
                    Name = app.Settings.SiteContactName,
                    Email = app.Settings.SiteContactEmail,
                    CellNumber = app.Settings.SiteContactCellPhone,

                    siteCode = app.Settings.SiteName,
                    oldContactName = oldContactName
                };
                await DoPost(app, "UpdateContact", c);
                return true;
            }
            catch (Exception exc)
            {
                await AddLog(app, "Network Error", string.Format("There was an error updating the contact at {0}.  MSG: {1}", DateTime.Now.ToString("yyyy/MM/dd HH:mm"), exc.Message));
                return false;
            }
        }

        private static async Task DoPost(App app, string action, object data)
        {
            await DoPost(app.Settings.WebServiceUrl, action, data, app.BatteryLevel);
        }
private static async Task DoPost(string baseUrl, string action, object data, int batteryLevel = -1)
        {
            var url = baseUrl + action;

            var postContent = GetHttpContentFromObject(data, batteryLevel);
            HttpResponseMessage response;
            using (var client = new HttpClient())
            {
                response = await client.PostAsync(url, postContent);
            }

            if (response.IsSuccessStatusCode == false)
            {
                throw new Exception(string.Format("Could not reach web service. Code:{0} MSG:{1}", response.StatusCode, response.Content.ToString()));
            }
            var contentVal = await response.Content.ReadAsStringAsync();

            if (contentVal != "")
            {
                throw new Exception(string.Format("Got an error from the web service.  MSG:" + contentVal));
            }


        }

        private static HttpContent GetHttpContentFromObject(object data, int batteryLevel = -1)
        {
            var kvp = new List<KeyValuePair<string, string>>();
            if (data != null)
            {
                var props = data.GetType().GetRuntimeProperties();
                if (props != null)
                {
                    foreach (var p in props)
                    {
                        try
                        {
                            var val = p.GetValue(data);
                            kvp.Add(new KeyValuePair<string, string>(p.Name, (val != null ? val.ToString() : "")));
                        }
                        catch(Exception exc)
                        {
                            var e = exc;
                        }
                    }
                }
                kvp.Add(new KeyValuePair<string, string>("batteryLevel", batteryLevel.ToString()));
            }
            return new FormUrlEncodedContent(kvp);
        }

Best Answer

Answers

  • FredyWengerFredyWenger CHInsider ✭✭✭✭✭

    @LoganMcKinley
    There are some problems with the debugger and the async events (don't stop as expected).
    The behavior is not logical sometimes,,,

    Therefore, I suggest you to debug to an emulator (on the MAC) and set breakpoints in all functions you have surround the call, to try findout between which functions it crashes and than which code-line exactly causes the problem.
    Sometimes there are crashes that suggest you, you have a problem with a httpget, but in real-life it is a problem with a ListView, where you want to show the data...

  • LoganMcKinleyLoganMcKinley USUniversity ✭✭

    Thanks for getting back to me.

    The problem is that it works as expected in the emulator.

  • prashantvcprashantvc USXamarin Team Xamurai
    edited October 2015

    Is it possible to send us the Device console log from the iPod touch? The console log will have detailed crash reporting, you can access the console log from XCode > Window > Devices
    and click on the small arrows down and it will show you the Logs.

  • LoganMcKinleyLoganMcKinley USUniversity ✭✭

    Below is the copy from the device log.

    Oct 12 08:33:50 ESETT-ipod-White lsd[80] : LaunchServices: Updating identifier store
    Oct 12 08:33:50 ESETT-ipod-White syncdefaultsd[788] : (Note ) SYDAlwaysOnAccount: no account (null)
    Oct 12 08:33:50 ESETT-ipod-White syncdefaultsd[788] : (Note ) SYDAccount: no account
    Oct 12 08:33:50 ESETT-ipod-White syncdefaultsd[788] : (Note ) SYDPIMAccount: no account (null)
    Oct 12 08:33:50 ESETT-ipod-White SpringBoard[54] : Installed apps did change.
    Added: {(
    )}
    Removed: {(
    )}
    Modified: {(
    "edu.virginia.ProtocolAssistDevice"
    )}
    Oct 12 08:33:50 ESETT-ipod-White SpringBoard[54] : could not find icon for representation -> com.your-company.SimpleAudioForms.iOS
    Oct 12 08:33:51 ESETT-ipod-White mobile_installation_proxy[168] : 0x16e1bb000 handle_connection: Could not receive request from host.
    Oct 12 08:33:52 ESETT-ipod-White com.apple.xpc.launchd[1] (lockdown.3094517796189.com.apple.mobile.mobile_image_mounter) : com.apple.mobile.mobile_image_mounter: This daemon is not allowed to execute. Running anyway.
    Oct 12 08:33:52 ESETT-ipod-White MobileStorageMounter[790] : 0x19d969000 iterate_ancestors: 263
    Oct 12 08:33:52 ESETT-ipod-White MobileStorageMounter[790] : 0x19d969000 iterate_ancestors: 263
    Oct 12 08:33:52 ESETT-ipod-White MobileStorageMounter[790] : 0x19d969000 iterate_ancestors: 263
    Oct 12 08:33:52 ESETT-ipod-White MobileStorageMounter[790] : 0x19d969000 iterate_ancestors: 263
    Oct 12 08:33:52 ESETT-ipod-White MobileStorageMounter[790] : 0x19d969000 iterate_ancestors: 263
    Oct 12 08:33:52 ESETT-ipod-White MobileStorageMounter[790] : 0x19d969000 iterate_ancestors: 263
    Oct 12 08:33:52 ESETT-ipod-White MobileStorageMounter[790] : 0x19d969000 iterate_ancestors: 263
    Oct 12 08:33:52 ESETT-ipod-White com.apple.xpc.launchd[1] (lockdown.3094524294977.com.apple.debugserver.applist) : com.apple.debugserver.applist: This daemon is not allowed to execute. Running anyway.
    Oct 12 08:33:52 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [791] : debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    for arm64.
    Oct 12 08:33:52 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [791] : Connecting to com.apple.debugserver service...
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    for arm64.
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : Connecting to com.apple.debugserver service...
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : Got a connection, waiting for process information for launching or attaching.
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : Sending AppProxy info: sequence no: 146, GUID: FBF4AAF0-2798-4927-8CD6-BFF3A817D2F0.
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : error: Unrecognized event type: . Ignoring.
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : About to launch process for bundle ID: edu.virginia.ProtocolAssistDevice
    Oct 12 08:33:53 ESETT-ipod-White amfid[171] : SecTrustEvaluate [leaf IssuerCommonName SubjectCommonName]
    Oct 12 08:33:53 ESETT-ipod-White kernel[0] : xpcproxy[793] Container: /private/var/mobile/Containers/Data/Application/8FE94862-BEB1-4BBF-9074-F9A88CBF511A (sandbox)
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : In completion handler, got pid for bundle id, pid: 793.
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : Got a connection, launched process /private/var/mobile/Containers/Bundle/Application/1D1D841E-A4DA-4478-9D0F-6F8ADDF4C665/ProtocolAssistDeviceiOS.app (pid = 793).
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : 1 +0.000000 sec [0318/0b07]: Disabling breakpoints and watchpoints, and detaching from 793.
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : 2 +0.000199 sec [0318/0b07]: error: ::ptrace (request = PT_THUPDATE, pid = 0x0319, tid = 0x3103, signal = -1) err = Invalid argument (0x00000016)
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : 3 +0.001011 sec [0318/1307]: error: ::read ( -1, 0x16e246a38, 1024 ) => -1 err = Bad file descriptor (0x00000009)
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [792] : Exiting.
    Oct 12 08:33:53 ESETT-ipod-White SpringBoard[54] : CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
    Oct 12 08:33:53 ESETT-ipod-White SpringBoard[54] : CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
    Oct 12 08:33:53 ESETT-ipod-White SpringBoard[54] : CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
    Oct 12 08:33:53 ESETT-ipod-White SpringBoard[54] : CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
    Oct 12 08:33:53 ESETT-ipod-White SpringBoard[54] : CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
    Oct 12 08:33:53 ESETT-ipod-White SpringBoard[54] : CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
    Oct 12 08:33:53 ESETT-ipod-White mobile_installation_proxy[168] : 0x16e247000 handle_connection: Could not receive request from host.
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [791] : 1 +0.000000 sec [0317/0b07]: error: ::read ( 6, 0x16fdd6c88, 1024 ) => 0 err = No such file or directory (0x00000002)
    Oct 12 08:33:53 ESETT-ipod-White com.apple.debugserver-@(#)PROGRAM:debugserver PROJECT:debugserver-340.3.51.1
    [791] : Exiting.
    Oct 12 08:33:53 ESETT-ipod-White mobile_installation_proxy[168] : 0x16e2d3000 handle_connection: Could not receive request from host.
    Oct 12 08:33:53 ESETT-ipod-White ProtocolAssistDeviceiOS[793] : Found new TLS offset at 224
    Oct 12 08:33:55 ESETT-ipod-White ProtocolAssistDeviceiOS[793] : The app delegate must implement the window property if it wants to use a main storyboard file.
    Oct 12 08:33:55 ESETT-ipod-White mediaserverd[25] : 08:33:55.917 WARNING: [0x16e1bb000] >va> 549: Unable to locate a set of sub-ports.
    Oct 12 08:33:55 ESETT-ipod-White kernel[0] : 128942.150098 wlan0.A[15021] [email protected]:get Message 0xe3ff8101
    Oct 12 08:33:55 ESETT-ipod-White mediaserverd[25] : 08:33:55.945 WARNING: [0x16e1bb000] >va> 549: Unable to locate a set of sub-ports.
    Oct 12 08:33:55 ESETT-ipod-White ProtocolAssistDeviceiOS[793] : Audio File Path: /private/var/mobile/Containers/Data/Application/8FE94862-BEB1-4BBF-9074-F9A88CBF511A/tmp/Recording 7624 20151012083355.m4a
    Oct 12 08:33:56 ESETT-ipod-White ProtocolAssistDeviceiOS[793] : starting recording as of 2015/10/12 08:33:56
    Oct 12 08:34:12 ESETT-ipod-White ProtocolAssistDeviceiOS[793] :
    Unhandled Exception:
    System.ExecutionEngineException: Attempting to JIT compile method 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder1<bool>:System.Runtime.CompilerServices.IAsyncMethodBuilder.PreBoxInitialization<TStateMachine> (TStateMachine&)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information. at System.Runtime.CompilerServices.AsyncMethodBuilderCore.GetCompletionAction[TMethodBuilder,TStateMachine] (System.Runtime.CompilerServices.TMethodBuilder& builder, System.Runtime.CompilerServices.TStateMachine& stateMachine) [0x0006a] in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:936 at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1[TResult].AwaitUnsafeOnCompleted[TAwaiter,TStateMachine] (System.Runtime.CompilerServices.TAwaiter& awaiter, System.Runtime.CompilerServices.TStateMachine& stateMachine) [0x00000] in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:516
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:line 143
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__1 (System.Object state) in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:line 1010
    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:line 1291
    at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, Boolean preserveSyncCtx) in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:line 581
    at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, Boolean preserveSyncCtx) in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:line 530
    at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:line 1268
    at System.Threading.ThreadPoolWorkQueue.Dispatch () in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:line 859
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:line 1196
    Oct 12 08:34:12 ESETT-ipod-White SpringBoard[54] : BSXPCMessage received error for message: Connection invalid
    Oct 12 08:34:12 ESETT-ipod-White SpringBoard[54] : BSXPCMessage received error for message: Connection invalid
    Oct 12 08:34:12 ESETT-ipod-White SpringBoard[54] : HW kbd: Failed to set (null) as keyboard focus
    Oct 12 08:34:12 ESETT-ipod-White com.apple.xpc.launchd[1] (UIKitApplication:edu.virginia.ProtocolAssistDevice[0x6082][793]) : Service exited with abnormal code: 255
    Oct 12 08:34:12 ESETT-ipod-White kernel[0] : 128958.376842 wlan0.A[15022] [email protected]:get Message 0xe3ff8101
    Oct 12 08:34:12 ESETT-ipod-White mediaserverd[25] : 08:34:12.172 WARNING: [0x16e12f000] >va> 549: Unable to locate a set of sub-ports.
    Oct 12 08:34:12 ESETT-ipod-White com.apple.xpc.launchd[1] (UIKitApplication:edu.virginia.ProtocolAssistDevice[0xbad0][794]) : Service could not initialize: 13A452: xpcproxy + 24412 [1472][748B91BC-19A2-393F-A49A-35C61779B011]: 0xd
    Oct 12 08:34:12 ESETT-ipod-White mediaserverd[25] : '' edu.virginia.ProtocolAssistDevice(pid = 793) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None
    Oct 12 08:34:12 ESETT-ipod-White SpringBoard[54] : Application 'UIKitApplication:edu.virginia.ProtocolAssistDevice[0x6082]' exited voluntarily.
    Oct 12 08:34:12 ESETT-ipod-White mediaserverd[25] : '' (pid = 793) setting DiscoveryMode = DiscoveryMode_None, currentDiscoveryMode = DiscoveryMode_None
    Oct 12 08:34:12 ESETT-ipod-White UserEventAgent[23] : 3095003776070: id=edu.virginia.ProtocolAssistDevice pid=793, state=0
    Oct 12 08:34:12 ESETT-ipod-White SpringBoard[54] : Unable to get pid for 'UIKitApplication:edu.virginia.ProtocolAssistDevice[0xbad0]': No such process (err 3)
    Oct 12 08:34:12 ESETT-ipod-White SpringBoard[54] : Bootstrapping failed for
    Oct 12 08:34:12 ESETT-ipod-White SpringBoard[54] : Unable to delete job with label UIKitApplication:edu.virginia.ProtocolAssistDevice[0xbad0]. Error: Operation now in progress
    Oct 12 08:34:12 ESETT-ipod-White SpringBoard[54] : Application 'UIKitApplication:edu.virginia.ProtocolAssistDevice[0xbad0]' exited for an unknown reason.
    Oct 12 08:34:13 ESETT-ipod-White backboardd[56] : |GAXGeneral|info| Did verify event: [Substantial Transition did occur]. Outcome: [Error - Session app was nil].
    Oct 12 08:34:45 ESETT-ipod-White syslogd[22] : ASL Sender Statistics
    Oct 12 08:34:52 ESETT-ipod-White syslog_relay[797] : syslog_relay read 51 total bytes:
    ========================
    ASL is here to serve you
    Oct 12 08:34:52 ESETT-ipod-White syslog_relay[797] : syslog_relay found the ASL prompt. Starting...
    Oct 12 08:39:13 ESETT-ipod-White SpringBoard[54] : [MPUSystemMediaControls] Disabling lock screen media controls updates for screen turning off.
    Oct 12 08:39:13 ESETT-ipod-White backboardd[56] : [HID] [MT] MTSimpleHIDManager::setPropertyInternal detection mode: 0->255
    Oct 12 08:39:14 ESETT-ipod-White kernel[0] : AppleKeyStore: operation failed (pid: 54 sel: 26 ret: e00002e2 '-536870174')
    Oct 12 08:39:13 ESETT-ipod-White UserEventAgent[23] : LockStateNotifier aksNotificationCallback posting notification: com.apple.mobile.keybagd.lock_status
    Oct 12 08:39:13 ESETT-ipod-White UserEventAgent[23] : (Note ) PIH: Lock status changed.
    Oct 12 08:39:14 ESETT-ipod-White MobileMail[141] : Key bag transitioning from unlocked to locking
    Oct 12 08:39:14 ESETT-ipod-White SpringBoard[54] : [MPUSystemMediaControls] Updating supported commands for now playing application.
    Oct 12 08:39:15 ESETT-ipod-White backboardd[56] : |GAXGeneral|info| Did verify event: [Substantial Transition did occur]. Outcome: [Error - Session app was nil].
    Oct 12 08:39:23 ESETT-ipod-White kernel[0] : AppleKeyStore:Sending lock change 1 for handle 0
    Oct 12 08:39:23 ESETT-ipod-White UserEventAgent[23] : LockStateNotifier aksNotificationCallback posting notification: com.apple.mobile.keybagd.lock_status
    Oct 12 08:39:23 ESETT-ipod-White UserEventAgent[23] : (Note ) PIH: Lock status changed.
    Oct 12 08:39:23 ESETT-ipod-White MobileMail[141] : Key bag transitioning from locking to locked

  • MarkSmith.8123MarkSmith.8123 USXamarin Team, University, XamUProfessors Xamurai

    @LoganMcKinley --

    It looks like the server is unreachable or it's timing out. I suggest you put a try/catch around your actual PostAsync call so you can get the exception details. Keep in mind that if this is on a background thread, it's eaten by the Thread Pool system and it won't show up anywhere useful for you.

    Also, you mention that it's coming back right away - where are you seeing this behavior? await essentially says continue forward execution for the main thread and continue running the remainder of this method later once the prior method returns. So, I would expect you to see it come back immediately with no result - the result gets filled in later because it's async. However, if the next line in the method is executed immediately, then it indicates something failed..

    Mark Smith
    Xamarin University | Curriculum

  • MarkSmith.8123MarkSmith.8123 USXamarin Team, University, XamUProfessors Xamurai

    One question - is this running on iOS9?
    If so, are you using the ModernHttpClient component from Nuget?
    If so, is the connection https?

    If all the above conditions are met, then you are under the control of the native networking stack and therefore ATS policy. Not sure if that's the case, let me know on that and I can tell you how to work around it.

  • LoganMcKinleyLoganMcKinley USUniversity ✭✭

    @MarkSmith.1116 : Thanks for getting back to me on this.

    1) Yes my device is running 9.0.2
    My App is a xamarin.forms app running Xamarin.Forms version 1.5.0.6447
    2) For the most part I have not been using ModernHttpClient, but I did just try it and I got the exact same result.
    3) For the most part I have been testing with https, butI also tested it with http and both got the same result. The most simple part of the API is http(s)://esettdev.azurewebsites.net/API/IsAlive which should simply return string.empty.

    I am not sure if it will help, but in there is a call stack in the Output -> Debug window:

    Launching 'ProtocolAssistDeviceiOS' on 'ESETT ipod (White)'...
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/System.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/Xamarin.iOS.dll [External]
    Launched 'ProtocolAssistDeviceiOS' successfully on 'ESETT ipod (White)'...
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/Mono.Dynamic.Interpreter.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/System.Core.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/System.Xml.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/Xamarin.Forms.Platform.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/Xamarin.Forms.Core.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/System.Net.Http.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/System.ServiceModel.Internals.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/System.Runtime.Serialization.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/Xamarin.Forms.Platform.iOS.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/Xamarin.Forms.Xaml.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/GalaSoft.MvvmLight.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/ModernHttpClient.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/Microsoft.Practices.ServiceLocation.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/GalaSoft.MvvmLight.Extras.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/ProtocolAssistDevice.dll
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/zxing.portable.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/ZXingNetMobile.dll [External]
    Loaded assembly: /private/var/mobile/Containers/Bundle/Application/1A30E8C2-2342-4DB6-AF12-943F0E42CFF4/ProtocolAssistDeviceiOS.app/.monotouch-64/ProtocolAssistDeviceiOS.exe
    Thread started: Finalizer #2
    2015-10-12 17:10:29.917 ProtocolAssistDeviceiOS[929:375230] The app delegate must implement the window property if it wants to use a main storyboard file.
    Thread started: #3
    Thread started: #4
    Thread started: #5
    Thread started: #6
    Thread started: #7
    2015-10-12 17:10:30.522 ProtocolAssistDeviceiOS[929:375230] Audio File Path: /private/var/mobile/Containers/Data/Application/76907521-1AAB-428B-9646-E8F301EEEF8F/tmp/Recording 7624 20151012171030.m4a
    2015-10-12 17:10:30.552 ProtocolAssistDeviceiOS[929:375230] starting recording as of 2015/10/12 17:10:30
    Resolved pending breakpoint at 'Battery.cs:27,1' to int ProtocolAssistDevice.iOS.Implementations.Battery.get_BatteryLevel () [0x00001].
    2015-10-12 17:10:30.754 ProtocolAssistDeviceiOS[929:375270] /var/mobile/Containers/Data/Application/76907521-1AAB-428B-9646-E8F301EEEF8F/Documents/7624 Logs.csv
    Resolved pending breakpoint at 'Networking.cs:227,1' to void ProtocolAssistDevice.Helpers.Networking.d__12.MoveNext () [0x00126].
    Resolved pending breakpoint at 'Networking.cs:240,1' to void ProtocolAssistDevice.Helpers.Networking.d__12.MoveNext () [0x0026a].
    Resolved pending breakpoint at 'Networking.cs:218,1' to void ProtocolAssistDevice.Helpers.Networking.d__12.MoveNext () [0x00029].
    Thread started: #8
    An unhandled exception occured.

    2015-10-12 17:10:46.238 ProtocolAssistDeviceiOS[929:375270]
    Unhandled Exception:
    System.ExecutionEngineException: Attempting to JIT compile method 'System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1:System.Runtime.CompilerServices.IAsyncMethodBuilder.PreBoxInitialization (TStateMachine&)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.

    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.GetCompletionAction[TMethodBuilder,TStateMachine] (System.Runtime.CompilerServices.TMethodBuilder& builder, System.Runtime.CompilerServices.TStateMachine& stateMachine) [0x0006a] in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:936
    at System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1[TResult].AwaitUnsafeOnCompleted[TAwaiter,TStateMachine] (System.Runtime.Compiler
    Services.TAwaiter& awaiter, System.Runtime.CompilerServices.TStateMachine& stateMachine) [0x00000] in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:516
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:line 143
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__1 (System.Object state) in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:line 1010
    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context (System.Object state) in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:line 1291
    at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, Boolean preserveSyncCtx) in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/executioncontext.cs:line 581
    at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, Boolean preserveSyncCtx) in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/refe
    rencesource/mscorlib/system/threading/executioncontext.cs:line 530
    at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:line 1268
    at System.Threading.ThreadPoolWorkQueue.Dispatch () in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:line 859
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () in /Users/builder/data/lanes/2097/b5396c29/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/threading/threadpool.cs:line 1196

  • LoganMcKinleyLoganMcKinley USUniversity ✭✭

    @MarkSmith.1116 ended up helping me off line with this.
    It turned out to be a couple problems:
    1) I was using ModernHttpClient, which routes through iOS. This has advantages of knowing information about device state at mono doesn't, but apple requires that you add specific exceptions for non https connections.
    2) The real problem though was that there appears to be a build problem with Xamarin in Visual Studio that causes a .dll that uses JIT to be included in the project. This works fine in the emulator, but you cannot use JIT on an Apple processor, so this was causing my hard/uncatchable crash. This appears to only affect Xamarin through VS and not builds done through Xamarin studio.

    My current work flow is that I am doing all of my initial debugging/testing in Visual Studio with the emulator, and when I am ready to do on device testing I load the solution in Xamarin Studio and build/deploy it through that to the device.

    Mark (and therefor Xamarin) deserves a lot of credit on figuring this out and getting me a work around reasonably quickly.

  • RLittlesRLittles USMember

    I am facing a very similar issue. I have a login service that was working a few days ago, now when I do HttpClient.PostAsync(Uri, content); my app crashes in the emulator. There doesn't appear to be an exception thrown. I am using ModernHttpClient, developing on Visual Studio and emulating on a networked Mac.

    One question - is this running on iOS9? => iOS 9.1
    If so, are you using the ModernHttpClient component from Nuget? => Yes
    If so, is the connection https? => No

    Output Window Debug:

    2016-01-06 17:51:38.046 MobileiOS[31561:6423897] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found. Did find: /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator 2016-01-06 17:51:38.047 MobileiOS[31561:6423897] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x7fdcfdd4be20 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded) 2016-01-06 17:51:38.047 MobileiOS[31561:6423897] Error loading /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: dlopen(/System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib, 262): no suitable image found. Did find: /System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin/Contents/MacOS/IOHIDLib: mach-o, but not built for iOS simulator 2016-01-06 17:51:38.048 MobileiOS[31561:6423897] Cannot find function pointer IOHIDLibFactory for factory 13AA9C44-6F1B-11D4-907C-0005028F18D5 in CFBundle/CFPlugIn 0x7fdcfdd4be20 </System/Library/Extensions/IOHIDFamily.kext/Contents/PlugIns/IOHIDLib.plugin> (bundle, not loaded) 2016-01-06 17:51:38.058 MobileiOS[31561:6423897] *** Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UIApplication.m:3299

  • RLittlesRLittles USMember

    I added logging to my API and determined that my requests are firing out. So I'll accept that it is my lack of understanding the TPL patterns.

  • arlvinarlvin Member

    Hi, i am facing a situation like the very first one reported. I am running my app on an LG G6 running Android 8.0. When i call "await httpClient.PostAsync()", the application crashes. However, when i use a blocking call, i.e. "httpClient.PostAsync().Result", the application runs fine. I've setup the app to to compile using Android 7, with "Minimum Target version" set to 4.4 and "Target Android version" set to Android 7.0.

    What could be the issue here?

Sign In or Register to comment.