title: Xamarin - Error when trying to read JSon
body: <p>I want my Android app to be able to get information from a site using Json and I'm using the Rest API to send and recieve that information, however things don't work as intended.
  It gives me a <code>java.lang.reflect.InvocationTargetException</code> and the debug output is as follows: </p>
  
  <pre><code>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] -&gt; 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] -&gt; /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] -&gt; /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] -&gt; 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] -&gt; 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] -&gt; 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] -&gt; System.Core[0x5f2e2958]: 2
  [Mono] Assembly Ref addref System.Core[0x5f2e2958] -&gt; 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] -&gt; Mono.Android[0x5aa7aaf8]: 2
  Loaded assembly: MonoDroidConstructors [External]
  [Mono] Assembly Ref addref HomecheckApp[0x5aa78f38] -&gt; mscorlib[0x41dd99b8]: 4
  [Mono] Image addref System.Json[0x61398b60] -&gt; 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] -&gt; System.Json[0x61398b60]: 2
  [Mono] Assembly Ref addref System.Json[0x61398b60] -&gt; mscorlib[0x41dd99b8]: 5
  Loaded assembly: System.Json.dll [External]
  [Mono] Image addref System[0x614bf570] -&gt; 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] -&gt; System[0x614bf570]: 2
  [Mono] Assembly Ref addref System[0x614bf570] -&gt; mscorlib[0x41dd99b8]: 6
  Loaded assembly: System.dll [External]
  [Mono] Assembly Ref addref Mono.Android[0x5aa7aaf8] -&gt; System[0x614bf570]: 3
  Thread started:  #2
  Thread started: &lt;Thread Pool&gt; #3
      Thread started: &lt;Thread Pool&gt; #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 () &lt;IL 0x00011, 0x00078&gt;
              [MonoDroid] at System.Runtime.CompilerServices.AsyncMethodBuilderCore.&lt;ThrowAsync&gt;m__0 (object) &lt;IL 0x00006, 0x0006b&gt;
                      [MonoDroid] at Android.App.SyncContext/&lt;Post&gt;c__AnonStorey0.&lt;&gt;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) &lt;IL 0x00011, 0x0003b&gt;
                              [art] JNI RegisterNativeMethods: attempt to register 0 native methods for md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable
                              [AndroidRuntime] Shutting down VM
  </code></pre>
  
  <p>The activity that handles the Json sharing:</p>
  
  <pre><code>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&lt;EditText&gt;(Resource.Id.editEmail);
              EditText password = FindViewById&lt;EditText&gt;(Resource.Id.editPassword);
              Button loginButton = FindViewById&lt;Button&gt;(Resource.Id.loginButton);
              loginButton.Click += async (sender, e) =&gt; {
                  string url = "http://homecheck/appapi/finduser";
                  JsonValue json = await FetchUserAsync(url);
              };
          }
  
          private async Task&lt;JsonValue&gt; 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(() =&gt; JsonObject.Load(stream));
                      Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());
                      return jsonDoc;
                  }
              }
          }
  
      }
  
  }
  </code></pre>
  
  <p>And finally the action in the MVC controller:</p>
  
  <pre><code> public function finduserAction() {
      $this-&gt;getResponse()
          -&gt;setHeader('Content-Type', 'application/json');
      $response = array('name' =&gt; 'test', 'version' =&gt; '1.0');
      $this-&gt;view-&gt;json = json_encode($response);
  }
  </code></pre>
  
  <p>What appears in the view:</p>
  
  <p><img src="https://i.stack.imgur.com/lU3hK.png" alt="enter image description here"></p>
  
  <p>If I type a different <code>string url</code> that returns Json (For example <a href="http://echo.jsontest.com/key/value/one/two" rel="nofollow noreferrer">http://echo.jsontest.com/key/value/one/two</a>) it works, so maybe the problem resides somewhere in the controller ?</p>