Forum Xamarin.Forms

System.Net.Http not found

Visual Studio 2015
Xamarin 3.9.289
Xamarin.Android 4.20.0.34

I have a basic almost hello world type app that is making a rest call with basic authentication.

This is the most relevant error message I see in the debug output window:

02-09 21:50:38.362 D/Mono ( 2514): AOT module 'System.Net.Http.dll.so' not found: dlopen failed: library "/data/data/ATD.Droid/lib/System.Net.Http.dll.so" not found

The error occurs when I step over the line below await response.Content.ReadAsStringAsync();

Any ideas on what might be causing this problem. I have reference system.net and system.net.http in the project.

Thanks
Brady

    public static async Task<T> GetAsync<T>(this HttpClient client, string url)
    {
        try {
            var httpRequest = new HttpRequestMessage(new HttpMethod("GET"), url);

            client.Timeout = TimeSpan.FromSeconds(30);

            string username = "consportapi";
            string password = "64ea2b32-d623-4e99-8683-7033ea4c70c5";
            string t = string.Format("{0}:{1}", username, password);
            byte[] bytes = Encoding.UTF8.GetBytes(string.Format("{0}:{1}", username, password));
            string b64t = Convert.ToBase64String(bytes);
            //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(string.Format("basic {0}", b64t));
            httpRequest.Headers.Add("Authorization", b64t);
            var response = await client.SendAsync(httpRequest);

            var jsonString = await response.Content.ReadAsStringAsync();

            var result = JsonConvert.DeserializeObject<T>(jsonString);

            return result;
        } catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
            return default(T);
        }
    }

Posts

  • I ran into this. Yeah its a show stopper.

  • JGarciaJGarcia USUniversity ✭✭

    I know this is very old, but in case someone ran into the same issue, the fix is manually adding the reference to
    System.Net.Http, and adding the nuget packages modernhttpclient and Microsoft Http Client ( at least on my case it worked correctly only after putting both of them)

  • BradyChambers.4907BradyChambers.4907 USMember ✭✭

    Thanks for the reply

  • I am having the same issue when using the FubarCoder.RestSharp.Portable library. I have added the System.Net.Http library manually in the android project and added the modernhttpclient package. But i do not understand which package is meant with the "Microsoft Http Client". @JGarcia Can you please clarify?

  • JGarciaJGarcia USUniversity ✭✭

    Go through the package manager and search for Microsoft.Net.Http and select Microsoft HTTP Client Libraries

    https://blogs.msdn.microsoft.com/bclteam/p/httpclient/

  • RoyvanderTuuk.3595RoyvanderTuuk.3595 USMember
    edited November 2016

    thanks for your reply unfortunetly this does not resolve my issues. I still get the following output when calling restsharp protable:

    11-30 19:26:52.460 D/Mono ( 2482): AOT module 'System.Net.Http.dll.so' not found: dlopen failed: library "/data/app-lib/com.skyliner.skyliner_app-2/libaot-System.Net.Http.dll.so" not found 11-30 19:26:52.472 D/Mono ( 2482): AOT module '/Users/builder/data/lanes/3511/77cb8568/source/monodroid/builds/install/mono-x86/lib/mono/aot-cache/x86/System.Net.Http.dll.so' not found: dlopen failed: library "/data/app-lib/com.skyliner.skyliner_app-2/libaot-System.Net.Http.dll.so" not found

  • VulcanVulcan TWMember ✭✭✭

    Could you upload your sample project source code for testing on my environment.

Sign In or Register to comment.