Resolve image loading error in Xamarin Forms
Hello everyone, I had an issue in my Xamarin.Forms project a while ago. The Issue was I could not load images from URLs into my Xamarin.Forms application. I was quite annoying, since on UWP, it loaded seamlessly. I tried using this cool plugin to load images in a better way, but I still had problems loading images from the internet into my app ?. It was quite annoying and I had to figure out what to do to solve this stuff, how could such an unexpected problem just happen to me magically. After asking Google, browsing Stackoverflow and Github issues, I realized many people had the same issue and some hadn’t succeeded in solving it. But as usual, the answer is hidden there somewhere and you need to find it.
If this is an of what you get in you project output, then you are at the right place:
ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri:
I had this because I was loading the image from an SSL URL (https:// …), due to this I could load the image. Resolving it was not that difficult, it was finding a solution which was. What you should do is that on android, settings modify your settings for selecting the HttpClient and TLS implementations as stated here by James Montemagno. Right click on your android project, select properties, Go to Android options and click on the Advanced button.
Change the HTTPClient and SSL/TLS inplementation to Managed and Native TLS 1.2+, Build and run and now you should be able to see your image loading without any problem.
Check on this article to have more information about securing web requests.
This is a short blog post, but it may be helpful to any one having this issue and needing to get around it as quick as possible.
If you liked this post, or it was useful to you, please like it, share it on twitter, facebook or other social media… in case you want to get updated on any new useful post, follow me on twitter and like my page on facebook.
Build a beautiful high quality apps with reactive ui and Xamarin.Forms get started here.