9

I have a demo xamarin forms project that simply displays an image with its image source set to a remote URL. But the problem is it works for some URL and does not for others. I have picked up random image links from google image search and compiled a list of the working / non-working ones. Any insight on this strange behavior is hugely appreciated.

Thanks in Advance!

Working URLs

Non-Working URLs

XAML file

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:XamarinImageTest"
             x:Class="XamarinImageTest.MainPage"
             BackgroundColor="#000000">

    <ContentPage.Content>
        <Image Source="https://i.ytimg.com/vi/JTxPzXQ1Sso/maxresdefault.jpg" 
               VerticalOptions="Fill"
               HorizontalOptions="Fill"></Image>
    </ContentPage.Content>
</ContentPage>
  • How do you implement the image display in Xamarin.forms? post with the codes or more information will be helpful to let the other to see the whole picture. – Json Nov 29 '17 at 10:35
  • Since you asked, I have attached the code also. I thought setting the source property of an image tag was obvious enough. :) – Sreejith Krishnadas Nov 29 '17 at 10:45
  • Looks like a caching problem. Try this library: https://github.com/luberda-molinet/FFImageLoading – EvZ Nov 29 '17 at 11:25
  • No luck.. Even FFImageLoading is giving the same results. I have made a sample github project (https://github.com/uksreejith/XamarinImageTest) demonstrating this issue. I wonder if it has something to do with URL redirection. – Sreejith Krishnadas Nov 29 '17 at 12:45
  • Tested with the given url, first and third not working url were able to display on iOS (Ver 11.1) except the second .png image and all of them were not able to display on Android (Ver 6.0). But those image were able to preview in the code breaking point, just not able to display on the phone. Also, I tested with some others image url, some images were not able to display if it is "https", but if rename it to "http", it will be able to displayed. but not in your case. Weird behaviour, seem like it is a bug. – Json Nov 29 '17 at 15:10
  • All the working URLs that I have given have an "https"..So i am not sure if that is an issue..It could be a bug..but both Xamarin and FFloadingimage are not able to load the images...Could they both have failed simultaneously? That's doubtful.. I haven't tested it on an iPhone.But if you are saying that it worked in iOS and not in android that just makes this case even more complicated.. – Sreejith Krishnadas Nov 29 '17 at 17:14

2 Answers2

3

Use native http client handlers + TLS2.0 for your app (can be set in project settings):

For iOS also enable http downloads:

Daniel Luberda
  • 7,374
  • 1
  • 32
  • 40
  • 1
    Thanks a ton..!! Switching to native http client handlers did the trick..I wonder what was wrong with the managed one though.. hmm..maybe a bug that needs fixing. – Sreejith Krishnadas Dec 06 '17 at 10:16
  • Can you confirm that this works with Xamarin.forms not just Xamarin.Android? It talks about "The Xamarin.Android HttpClient configuration is in Project Options > Android Options, then click the Advanced Options button." - I can't see 'project options' or 'advanced' or anything similar in my xamarin forms app! – niico Oct 17 '19 at 14:29
  • @niico You should check the Properties for MyProject.Android. There you will find Android Options which has an Advanced button at the end. But it didn't work for me. – mrmowji Oct 20 '19 at 07:31
  • 2
    To future debuggers: Make sure you have the most recent version of Xamarin.Forms package installed (I had 4.2.0.709249 and I updated to 4.2.0.848062). And make sure you've changed the image source URL before building/deploying the app, because images get cached for 24 hours. – mrmowji Oct 20 '19 at 09:40
2

I had this issue. Remote images would display in UWP and ISO, but would not display in Android. What worked was updating the NuGet Xamarin packages.