Xamarin - Error trying to read JSon

I want my android app to be able to receive information from the site using Json and I am using the Rest API to send and receive this information, however things are not working as planned. It gives me java.lang.reflect.InvocationTargetException

, and the debug output looks like this:

Forwarding debugger port 8842
Detecting existing process
Loaded assembly: /storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/HomecheckApp.dll
Loaded assembly: /storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/RestSharp.MonoDroid.dll [External]
Loaded assembly: Mono.Android.dll [External]
[art] Late-enabling -Xcheck:jni
[monodroid] Using override path: /data/data/eu.COMPANY_NAME.homecheckapp/files/.__override__
[monodroid] Using override path: /storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__
[monodroid] Trying to load sgen from: /data/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/libmonosgen-2.0.so
[monodroid] Trying to load sgen from: /storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/libmonosgen-2.0.so
[monodroid] Trying to load sgen from: /data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libmonosgen-2.0.so
[monodroid] Trying to load sgen from: /data/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/links/libmonosgen-2.0.so
[monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8842,server=y,embedding=1
[Mono] Image addref mscorlib[0x41dd99b8] -> mscorlib.dll[0x60df5ac8]: 1
[Mono] AOT module 'mscorlib.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-mscorlib.dll.so" not found
[Mono] AOT module '/Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/mscorlib.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-mscorlib.dll.so" not found
[Mono] Assembly mscorlib[0x41dd99b8] added to domain RootDomain, ref_count=1
[Mono] Assembly Loader probing location: '/storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/HomecheckApp.dll'.
[Mono] Image addref HomecheckApp[0x5aa78f38] -> /storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/HomecheckApp.dll[0x5aa782d8]: 2
[Mono] Assembly HomecheckApp[0x5aa78f38] added to domain RootDomain, ref_count=1
[Mono] AOT module '/storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/HomecheckApp.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-HomecheckApp.dll.so" not found
[Mono] AOT module '/Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/HomecheckApp.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-HomecheckApp.dll.so" not found
[Mono] Assembly Loader loaded assembly from location: '/storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/HomecheckApp.dll'.
[Mono] Config attempting to parse: '/storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/HomecheckApp.dll.config'.
[Mono] Config attempting to parse: '/Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/builds/install/mono-armv7/etc/mono/assemblies/HomecheckApp/HomecheckApp.config'.
[Mono] Assembly Loader probing location: '/storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/RestSharp.MonoDroid.dll'.
[Mono] Image addref RestSharp.MonoDroid[0x5aa79e60] -> /storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/RestSharp.MonoDroid.dll[0x5aa79218]: 2
[Mono] Assembly RestSharp.MonoDroid[0x5aa79e60] added to domain RootDomain, ref_count=1
[Mono] AOT module '/storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/RestSharp.MonoDroid.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-RestSharp.MonoDroid.dll.so" not found
[Mono] AOT module '/Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/RestSharp.MonoDroid.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-RestSharp.MonoDroid.dll.so" not found
[Mono] Assembly Loader loaded assembly from location: '/storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/RestSharp.MonoDroid.dll'.
[Mono] Config attempting to parse: '/storage/emulated/0/Android/data/eu.COMPANY_NAME.homecheckapp/files/.__override__/RestSharp.MonoDroid.dll.config'.
[Mono] Config attempting to parse: '/Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/builds/install/mono-armv7/etc/mono/assemblies/RestSharp.MonoDroid/RestSharp.MonoDroid.config'.
[monodroid-gc] GREF GC Threshold: 46080
[Mono] Image addref Mono.Android[0x5aa7aaf8] -> Mono.Android.dll[0x5aa79f80]: 1
[Mono] Assembly Mono.Android[0x5aa7aaf8] added to domain RootDomain, ref_count=1
[Mono] AOT module 'Mono.Android.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-Mono.Android.dll.so" not found
[Mono] AOT module '/Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/Mono.Android.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-Mono.Android.dll.so" not found
[Mono] Assembly Ref addref Mono.Android[0x5aa7aaf8] -> mscorlib[0x41dd99b8]: 2
[Mono] DllImport attempting to load: '__Internal'.
[Mono] DllImport loaded library '(null)'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for '_monodroid_lref_log_new'.
[Mono] Probing '_monodroid_lref_log_new'.
[Mono] Found as '_monodroid_lref_log_new'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for '_monodroid_lref_log_delete'.
[Mono] Probing '_monodroid_lref_log_delete'.
[Mono] Found as '_monodroid_lref_log_delete'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for '_monodroid_gref_log_new'.
[Mono] Probing '_monodroid_gref_log_new'.
[Mono] Found as '_monodroid_gref_log_new'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for '_monodroid_get_identity_hash_code'.
[Mono] Probing '_monodroid_get_identity_hash_code'.
[Mono] Found as '_monodroid_get_identity_hash_code'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for '_monodroid_gref_log'.
[Mono] Probing '_monodroid_gref_log'.
[Mono] Found as '_monodroid_gref_log'.
[Mono] Image addref System.Core[0x5f2e2958] -> System.Core.dll[0x5f2e1f70]: 1
[Mono] Assembly System.Core[0x5f2e2958] added to domain RootDomain, ref_count=1
[Mono] AOT module 'System.Core.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-System.Core.dll.so" not found
[Mono] AOT module '/Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/System.Core.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-System.Core.dll.so" not found
[Mono] Assembly Ref addref Mono.Android[0x5aa7aaf8] -> System.Core[0x5f2e2958]: 2
[Mono] Assembly Ref addref System.Core[0x5f2e2958] -> mscorlib[0x41dd99b8]: 3
Loaded assembly: System.Core.dll [External]
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for '_monodroid_gref_log_delete'.
[Mono] Probing '_monodroid_gref_log_delete'.
[Mono] Found as '_monodroid_gref_log_delete'.
[Mono] DllImport searching in: '__Internal' ('(null)').
[Mono] Searching for '_monodroid_gc_wait_for_bridge_processing'.
[Mono] Probing '_monodroid_gc_wait_for_bridge_processing'.
[Mono] Found as '_monodroid_gc_wait_for_bridge_processing'.
[monodroid] Xamarin/Android Trial Mode Active
[OpenGLRenderer] Use EGL_SWAP_BEHAVIOR_PRESERVED: false
[Atlas] Validating map...
[libEGL] loaded /system/lib/egl/libEGL_tegra.so
[libEGL] loaded /system/lib/egl/libGLESv1_CM_tegra.so
[libEGL] loaded /system/lib/egl/libGLESv2_tegra.so
[OpenGLRenderer] Initialized EGL, version 1.4
[OpenGLRenderer] Enabling debug mode 0
[Mono] Assembly Ref addref HomecheckApp[0x5aa78f38] -> Mono.Android[0x5aa7aaf8]: 2
Loaded assembly: MonoDroidConstructors [External]
[Mono] Assembly Ref addref HomecheckApp[0x5aa78f38] -> mscorlib[0x41dd99b8]: 4
[Mono] Image addref System.Json[0x61398b60] -> System.Json.dll[0x614b24a8]: 1
[Mono] Assembly System.Json[0x61398b60] added to domain RootDomain, ref_count=1
[Mono] AOT module 'System.Json.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-System.Json.dll.so" not found
[Mono] AOT module '/Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/System.Json.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-System.Json.dll.so" not found
[Mono] Assembly Ref addref HomecheckApp[0x5aa78f38] -> System.Json[0x61398b60]: 2
[Mono] Assembly Ref addref System.Json[0x61398b60] -> mscorlib[0x41dd99b8]: 5
Loaded assembly: System.Json.dll [External]
[Mono] Image addref System[0x614bf570] -> System.dll[0x614dd030]: 1
[Mono] Assembly System[0x614bf570] added to domain RootDomain, ref_count=1
[Mono] AOT module 'System.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-System.dll.so" not found
[Mono] AOT module '/Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/System.dll.so' not found: dlopen failed: library "/data/app/eu.COMPANY_NAME.homecheckapp-1/lib/arm/libaot-System.dll.so" not found
[Mono] Assembly Ref addref HomecheckApp[0x5aa78f38] -> System[0x614bf570]: 2
[Mono] Assembly Ref addref System[0x614bf570] -> mscorlib[0x41dd99b8]: 6
Loaded assembly: System.dll [External]
[Mono] Assembly Ref addref Mono.Android[0x5aa7aaf8] -> System[0x614bf570]: 3
Thread started:  #2
Thread started: <Thread Pool> #3
    Thread started: <Thread Pool> #4
        [Mono] DllImport attempting to load: '/system/lib/libc.so'.
        [Mono] DllImport loaded library '/system/lib/libc.so'.
        [Mono] DllImport searching in: '/system/lib/libc.so' ('/system/lib/libc.so').
        [Mono] Searching for 'gettid'.
        [Mono] Probing 'gettid'.
        [Mono] Found as 'gettid'.
        [Mono] DllImport attempting to load: '/system/lib/liblog.so'.
        [Mono] DllImport loaded library '/system/lib/liblog.so'.
        [Mono] DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so').
        [Mono] Searching for '__android_log_print'.
        [Mono] Probing '__android_log_print'.
        [Mono] Found as '__android_log_print'.
        [MonoDroid] UNHANDLED EXCEPTION:
        [MonoDroid] System.Net.WebException: Error: NameResolutionFailure
        [MonoDroid] at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <IL 0x00011, 0x00078>
            [MonoDroid] at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (object) <IL 0x00006, 0x0006b>
                    [MonoDroid] at Android.App.SyncContext/<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:18
                        [MonoDroid] at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
                        [MonoDroid] at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/1879/5f55a9ef/source/monodroid/src/Mono.Android/platforms/android-19/src/generated/Java.Lang.IRunnable.cs:71
                        [MonoDroid] at (wrapper dynamic-method) object.64d78430-69a4-4af6-bd73-cd5a21882790 (intptr,intptr) <IL 0x00011, 0x0003b>
                            [art] JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
                            [AndroidRuntime] Shutting down VM

      

Activity that handles Json sharing:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Json;
using System.Net;
using System.IO;
using System.Threading.Tasks;

namespace HomecheckApp {
    [Activity(Label = "LoginActivity", MainLauncher = true)]            
    public class LoginActivity : Activity {
        protected override void OnCreate(Bundle bundle) {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Login);
            EditText email = FindViewById<EditText>(Resource.Id.editEmail);
            EditText password = FindViewById<EditText>(Resource.Id.editPassword);
            Button loginButton = FindViewById<Button>(Resource.Id.loginButton);
            loginButton.Click += async (sender, e) => {
                string url = "http://homecheck/appapi/finduser";
                JsonValue json = await FetchUserAsync(url);
            };
        }

        private async Task<JsonValue> FetchUserAsync(string url) {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
            request.ContentType = "application/json";
            request.Method = "GET";
            using(WebResponse response = await request.GetResponseAsync()) {
                using(Stream stream = response.GetResponseStream()) {
                    JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));
                    Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());
                    return jsonDoc;
                }
            }
        }

    }

}

      

And finally the action in the MVC controller:

 public function finduserAction() {
    $this->getResponse()
        ->setHeader('Content-Type', 'application/json');
    $response = array('name' => 'test', 'version' => '1.0');
    $this->view->json = json_encode($response);
}

      

What is displayed in the view:

enter image description here

If I find another string url

that returns Json (eg http://echo.jsontest.com/key/value/one/two ) it works, so maybe the problem is somewhere in the controller?

+3


source to share


1 answer


As mentioned, the device from which you are debugging the application cannot resolve " http: // homecheck / appapi / finduser " because it does not work "Don't know host host".

Probaby you are using your API application locally. Try deploying it to a public server or setting up local DNS to route homecheck to the computer that is running your API application.



If you can provide some information about your setup eg. you are using a real android device, what webserver are you using in your API app, maybe we can help you solve your problem.

+1


source







All Articles