locked
Error: Webservice works totally fine in Android, but crashes in the iOS- ipad . RRS feed

  • Question

  • User358670 posted

    Hello; I am trying to execute the following code by calling the OpenView() function in the page constructor, inorder to retrieve data from the webservice and fill it up in a picker called servicePicker via an arraylist called services ;

    async void OpenView() { Uri requestUri = new Uri("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); dynamic dynamicJson = new ExpandoObject();

            try
            {
                dynamicJson.MaintenanceType = "emergency";
                dynamicJson.FacilitiesName = "";
                dynamicJson.Language = "en";
    
            string jsonData = "";
            jsonData = Newtonsoft.Json.JsonConvert.SerializeObject(dynamicJson);
            var objClint = new System.Net.Http.HttpClient();
            System.Net.Http.HttpResponseMessage respon = await objClint.PostAsync(requestUri, new StringContent(jsonData, System.Text.Encoding.UTF8, "application/json"));
            string responJsonText = await respon.Content.ReadAsStringAsync();
            RootObject rootObject = JsonConvert.DeserializeObject<RootObject>(responJsonText);
    
    
            for (int i = 0; i < rootObject.ServiceType.Count; i++)
            {
                services.Add(rootObject.ServiceType[i].Value);
            }
            servicePicker.ItemsSource = services;
            if (services.Count > 0)
            {
                Testing.IsRunning = false;
                Testing.IsVisible = false;
            }
            }
            catch (Exception ex)
            {
                DisplayAlert("Test", ex.ToString(), "OK");
            }
        }
    

    This works totally fine in Android, but crashes in the iOS- ipad . The issue is making me crazy :( . Please help. The exception I get is System.ArgumentException: Value cannot be null.

    Here are error details: System.ArgumentNullException: Value cannot be null. Parameter name: method at System.Linq.Expressions.Expression.Call (System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Collections.Generic.IEnumerable1[T] arguments) [0x00111] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/MethodCallExpression.cs:1239 at System.Linq.Expressions.Expression.Call (System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Linq.Expressions.Expression[] arguments) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/MethodCallExpression.cs:1046 at System.Linq.Expressions.Expression.Call (System.Reflection.MethodInfo method, System.Linq.Expressions.Expression[] arguments) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/MethodCallExpression.cs:1001 at System.Dynamic.ExpandoObject+MetaExpando.BindSetMember (System.Dynamic.SetMemberBinder binder, System.Dynamic.DynamicMetaObject value) [0x00033] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Dynamic/ExpandoObject.cs:863 at System.Dynamic.SetMemberBinder.Bind (System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args) [0x00035] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Dynamic/SetMemberBinder.cs:57 at System.Dynamic.DynamicMetaObjectBinder.Bind (System.Object[] args, System.Collections.ObjectModel.ReadOnlyCollection1[T] parameters, System.Linq.Expressions.LabelTarget returnLabel) [0x000c6] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Dynamic/DynamicMetaObjectBinder.cs:90 at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T] (System.Runtime.CompilerServices.CallSite1[T] site, System.Object[] args) [0x00019] in <773264786149499a986a13db6a7d46fe>:0 at System.Runtime.CompilerServices.CallSiteOps.Bind[T] (System.Runtime.CompilerServices.CallSiteBinder binder, System.Runtime.CompilerServices.CallSite1[T] site, System.Object[] args) [0x00000] in <773264786149499a986a13db6a7d46fe>:0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:305 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151 at System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow (System.Reflection.TargetInvocationException exception) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Utilities.cs:174 at System.Linq.Expressions.Interpreter.MethodInfoCallInstruction.Run (System.Linq.Expressions.Interpreter.InterpretedFrame frame) [0x00035] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/CallInstruction.cs:333 at System.Linq.Expressions.Interpreter.Interpreter.Run (System.Linq.Expressions.Interpreter.InterpretedFrame frame) [0x00015] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/external/corefx/src/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/Interpreter.cs:63 at System.Linq.Expressions.Interpreter.LightLambda.Run3[T0,T1,T2,TRet] (T0 arg0, T1 arg1, T2 arg2) [0x00038] in <773264786149499a986a13db6a7d46fe>:0 at App1.SnapFix+d__31.MoveNext () [0x00031] in C:\Users\mjehangir\source\repos\App1\App1\App1\SnapFix.xaml.cs:199

    Tuesday, January 9, 2018 8:22 AM

Answers

  • User171749 posted

    Try adding this to your info.plist

    XAML <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key><true/>
    </dict>

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, January 9, 2018 8:24 AM
  • User89714 posted

    @MJ_Ahmed - If the exception is being thrown on the line

    dynamicJson.MaintenanceType = "emergency";

    show the definition/code for ExpandoObject.MaintenanceType.

    However, be aware that your use of async/await is likely to cause problems. As per many other forum threads, avoid calling async methods from constructors. Also, ensure async methods are awaited, avoid async void (other than top-level event handlers), and for ease of reading ensure any async methods you create have Async appended to their name.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, January 9, 2018 9:23 AM

All replies

  • User171749 posted

    Try adding this to your info.plist

    XAML <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key><true/>
    </dict>

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, January 9, 2018 8:24 AM
  • User358670 posted

    @seanyda said: Try adding this to your info.plist

    XAML <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key><true/>
    </dict>

    Thanks for the response...

    This is my info plist, looks like I already had it but the issue exists even though :( ..

    UIDeviceFamily 1 2

    <key>NSCameraUsageDescription</key>
    <string>This app needs access to the camera to take photos.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>This app needs access to photos.</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>This app needs access to microphone.</string>
    <key>NSCalendarsUsageDescription</key>
    <string>This app needs access to Calendar.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This app needs access to the location services.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app needs access to the location and GPS services.</string>
    
    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>MinimumOSVersion</key>
    <string>8.0</string>
    <key>CFBundleDisplayName</key>
    <string>App1</string>
    <key>CFBundleIdentifier</key>
    <string>xxxxxxxxxxxxxxxxxxx</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>CFBundleIconFiles</key>
    <array>
      <string>Icon-60@2x</string>
      <string>Icon-60@3x</string>
      <string>Icon-76</string>
      <string>Icon-76@2x</string>
      <string>Default</string>
      <string>Default@2x</string>
      <string>Default-568h@2x</string>
      <string>Default-Portrait</string>
      <string>Default-Portrait@2x</string>
      <string>Icon-Small-40</string>
      <string>Icon-Small-40@2x</string>
      <string>Icon-Small-40@3x</string>
      <string>Icon-Small</string>
      <string>Icon-Small@2x</string>
      <string>Icon-Small@3x</string>
    </array>
    
    
    
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLName</key>
        <string>URL Type 1</string>
      </dict>
    </array>
    
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key><true/>
    </dict>
    

    Tuesday, January 9, 2018 8:30 AM
  • User171749 posted

    @MJ_Ahmed said:

    @seanyda said: Try adding this to your info.plist

    XAML <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key><true/>
    </dict>

    Thanks for the response...

    This is my info plist, looks like I already had it but the issue exists even though :( ..

    UIDeviceFamily 1 2

    <key>NSCameraUsageDescription</key>
    <string>This app needs access to the camera to take photos.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>This app needs access to photos.</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>This app needs access to microphone.</string>
    <key>NSCalendarsUsageDescription</key>
    <string>This app needs access to Calendar.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This app needs access to the location services.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app needs access to the location and GPS services.</string>
    
    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>MinimumOSVersion</key>
    <string>8.0</string>
    <key>CFBundleDisplayName</key>
    <string>App1</string>
    <key>CFBundleIdentifier</key>
    <string>xxxxxxxxxxxxxxxxxxx</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>CFBundleIconFiles</key>
    <array>
      <string>Icon-60@2x</string>
      <string>Icon-60@3x</string>
      <string>Icon-76</string>
      <string>Icon-76@2x</string>
      <string>Default</string>
      <string>Default@2x</string>
      <string>Default-568h@2x</string>
      <string>Default-Portrait</string>
      <string>Default-Portrait@2x</string>
      <string>Icon-Small-40</string>
      <string>Icon-Small-40@2x</string>
      <string>Icon-Small-40@3x</string>
      <string>Icon-Small</string>
      <string>Icon-Small@2x</string>
      <string>Icon-Small@3x</string>
    </array>
    
    
    
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLName</key>
        <string>URL Type 1</string>
      </dict>
    </array>
    
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key><true/>
    </dict>
    

    What line is the exception being thrown on?

    Tuesday, January 9, 2018 8:32 AM
  • User358670 posted

    @seanyda said:

    @MJ_Ahmed said:

    @seanyda said: Try adding this to your info.plist

    XAML <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key><true/>
    </dict>

    Thanks for the response...

    This is my info plist, looks like I already had it but the issue exists even though :( ..

    UIDeviceFamily 1 2

    <key>NSCameraUsageDescription</key>
    <string>This app needs access to the camera to take photos.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>This app needs access to photos.</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>This app needs access to microphone.</string>
    <key>NSCalendarsUsageDescription</key>
    <string>This app needs access to Calendar.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This app needs access to the location services.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app needs access to the location and GPS services.</string>
    
    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>MinimumOSVersion</key>
    <string>8.0</string>
    <key>CFBundleDisplayName</key>
    <string>App1</string>
    <key>CFBundleIdentifier</key>
    <string>xxxxxxxxxxxxxxxxxxx</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>CFBundleIconFiles</key>
    <array>
      <string>Icon-60@2x</string>
      <string>Icon-60@3x</string>
      <string>Icon-76</string>
      <string>Icon-76@2x</string>
      <string>Default</string>
      <string>Default@2x</string>
      <string>Default-568h@2x</string>
      <string>Default-Portrait</string>
      <string>Default-Portrait@2x</string>
      <string>Icon-Small-40</string>
      <string>Icon-Small-40@2x</string>
      <string>Icon-Small-40@3x</string>
      <string>Icon-Small</string>
      <string>Icon-Small@2x</string>
      <string>Icon-Small@3x</string>
    </array>
    
    
    
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLName</key>
        <string>URL Type 1</string>
      </dict>
    </array>
    
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key><true/>
    </dict>
    

    What line is the exception being thrown on?

    In the code, within the try block, the exception is thrown at => dynamicJson.MaintenanceType = "emergency";

    Tuesday, January 9, 2018 8:33 AM
  • User358670 posted

    @seanyda said:

    @MJ_Ahmed said:

    @seanyda said: Try adding this to your info.plist

    XAML <key>NSAppTransportSecurity</key>
    <dict>
    <key>NSAllowsArbitraryLoads</key><true/>
    </dict>

    Thanks for the response...

    This is my info plist, looks like I already had it but the issue exists even though :( ..

    UIDeviceFamily 1 2

    <key>NSCameraUsageDescription</key>
    <string>This app needs access to the camera to take photos.</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>This app needs access to photos.</string>
    <key>NSMicrophoneUsageDescription</key>
    <string>This app needs access to microphone.</string>
    <key>NSCalendarsUsageDescription</key>
    <string>This app needs access to Calendar.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>This app needs access to the location services.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>This app needs access to the location and GPS services.</string>
    
    <key>UISupportedInterfaceOrientations</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortraitUpsideDown</string>
      <string>UIInterfaceOrientationPortrait</string>
      <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>MinimumOSVersion</key>
    <string>8.0</string>
    <key>CFBundleDisplayName</key>
    <string>App1</string>
    <key>CFBundleIdentifier</key>
    <string>xxxxxxxxxxxxxxxxxxx</string>
    <key>CFBundleVersion</key>
    <string>1.0</string>
    <key>CFBundleIconFiles</key>
    <array>
      <string>Icon-60@2x</string>
      <string>Icon-60@3x</string>
      <string>Icon-76</string>
      <string>Icon-76@2x</string>
      <string>Default</string>
      <string>Default@2x</string>
      <string>Default-568h@2x</string>
      <string>Default-Portrait</string>
      <string>Default-Portrait@2x</string>
      <string>Icon-Small-40</string>
      <string>Icon-Small-40@2x</string>
      <string>Icon-Small-40@3x</string>
      <string>Icon-Small</string>
      <string>Icon-Small@2x</string>
      <string>Icon-Small@3x</string>
    </array>
    
    
    
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>CFBundleURLTypes</key>
    <array>
      <dict>
        <key>CFBundleURLName</key>
        <string>URL Type 1</string>
      </dict>
    </array>
    
    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSAllowsArbitraryLoads</key><true/>
    </dict>
    

    What line is the exception being thrown on?

    Hi again; I just found out that dynamic json isnt supported on xamarin ios. So used an alternative of json object serialization. Thanks for ur time :) My problem got resolved.

    Tuesday, January 9, 2018 9:22 AM
  • User89714 posted

    @MJ_Ahmed - If the exception is being thrown on the line

    dynamicJson.MaintenanceType = "emergency";

    show the definition/code for ExpandoObject.MaintenanceType.

    However, be aware that your use of async/await is likely to cause problems. As per many other forum threads, avoid calling async methods from constructors. Also, ensure async methods are awaited, avoid async void (other than top-level event handlers), and for ease of reading ensure any async methods you create have Async appended to their name.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, January 9, 2018 9:23 AM