Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri #7751

Closed
developer9969 opened this issue Sep 30, 2019 · 43 comments

Comments

@developer9969
Copy link

developer9969 commented Sep 30, 2019

Description

Image does not load
It was allegedly fixed in
#5172 7248

but latest comment there

Steps to Reproduce

  1. Download project from
    https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/workingwithimages/

  2. update to latest xamarin forms

  3. Launch android and you will get in output
    ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri: https://aka.ms/campus.jpg

Expected Behavior

Load the image

Actual Behavior

Does not show image

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE: Visual studio 2019 16.3.1
  • Platform Target Frameworks: XF 4.2.0.815419
    • Android: Android 9.0

Screenshots

Reproduction Link

@developer9969 developer9969 added s/unverified New report that has yet to be verified t/bug 🐛 labels Sep 30, 2019
@PureWeen
Copy link
Contributor

@developer9969 we recently fixed an issue with this that should be in the release you mentioned

I tested that sample on an Samsung S9 (API 28) and API 25 Simulator and in both cases it worked for me

Can you make sure the device has internet connectivity? Can you try updating to the latest 4.3 pre? or try the latest nightly builds?

https://github.com/xamarin/Xamarin.Forms/wiki/Nightly-Builds

@PureWeen PureWeen added the s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. label Sep 30, 2019
@developer9969
Copy link
Author

@PureWeen thanks for your prompt reply. just tried now on emulator.Will try on device as soon as get home, but at work I tried on s9 and sony and did not work. Does work in iOS emulator and device.

Tried latest xamarin and prerelease 4.3 and nothing.. I get the following ,below is just a section.
I definetely have internet! Did not try nightly build.

image

Thread started: #4
Thread started: #5
Thread started: #6
09-30 18:58:20.052 D/Mono ( 7470): Loading reference 9 of /storage/emulated/0/Android/data/com.YourCompany.WorkingWithImages/files/.override/Xamarin.Android.Support.Fragment.dll asmctx DEFAULT, looking for Xamarin.Android.Support.ViewPager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
09-30 18:58:20.052 D/Mono ( 7470): Assembly Ref addref Xamarin.Android.Support.Fragment[0xf1c42c80] -> Xamarin.Android.Support.ViewPager[0xf1c437c0]: 4
09-30 18:58:20.141 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:20.141 D/Mono ( 7470): Searching for 'java_interop_jnienv_call_static_int_method_a'.
09-30 18:58:20.141 D/Mono ( 7470): Probing 'java_interop_jnienv_call_static_int_method_a'.
09-30 18:58:20.142 D/Mono ( 7470): Found as 'java_interop_jnienv_call_static_int_method_a'.
09-30 18:58:20.170 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:20.170 D/Mono ( 7470): Searching for 'java_interop_jnienv_new_string'.
09-30 18:58:20.171 D/Mono ( 7470): Probing 'java_interop_jnienv_new_string'.
09-30 18:58:20.171 D/Mono ( 7470): Found as 'java_interop_jnienv_new_string'.
09-30 18:58:20.179 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:20.179 D/Mono ( 7470): Searching for 'java_interop_jnienv_new_local_ref'.
09-30 18:58:20.179 D/Mono ( 7470): Probing 'java_interop_jnienv_new_local_ref'.
09-30 18:58:20.179 D/Mono ( 7470): Found as 'java_interop_jnienv_new_local_ref'.
09-30 18:58:20.207 D/Mono ( 7470): Loading reference 6 of Mono.Android.dll asmctx DEFAULT, looking for System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
09-30 18:58:20.207 D/Mono ( 7470): Assembly Ref addref Mono.Android[0xf1c43b80] -> System.Xml[0xd1e1f6c0]: 3
09-30 18:58:20.214 D/Mono ( 7470): Loading reference 10 of netstandard.dll asmctx DEFAULT, looking for System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
09-30 18:58:20.214 D/Mono ( 7470): Image addref System.Runtime.Serialization[0xd1e21520] (asmctx DEFAULT) -> System.Runtime.Serialization.dll[0xd1e26d00]: 2
09-30 18:58:20.215 D/Mono ( 7470): Prepared to set up assembly 'System.Runtime.Serialization' (System.Runtime.Serialization.dll)
09-30 18:58:20.215 D/Mono ( 7470): Assembly System.Runtime.Serialization[0xd1e21520] added to domain RootDomain, ref_count=1
09-30 18:58:20.223 D/Mono ( 7470): AOT: image 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "System.Runtime.Serialization.dll.so" not found
09-30 18:58:20.224 D/Mono ( 7470): AOT: image '/Users/builder/jenkins/workspace/archive-mono/2019-06/android/release/sdks/out/android-x86-release/lib/mono/aot-cache/x86/System.Runtime.Serialization.dll.so' not found: (null)
09-30 18:58:20.224 D/Mono ( 7470): Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
09-30 18:58:20.224 D/Mono ( 7470): Config attempting to parse: '/Users/builder/jenkins/workspace/archive-mono/2019-06/android/release/sdks/out/android-x86-release/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
09-30 18:58:20.224 D/Mono ( 7470): Assembly Ref addref netstandard[0xebd87e80] -> System.Runtime.Serialization[0xd1e21520]: 2
09-30 18:58:20.224 D/Mono ( 7470): Loading reference 0 of System.Runtime.Serialization.dll asmctx DEFAULT, looking for mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
09-30 18:58:20.224 D/Mono ( 7470): Assembly Ref addref System.Runtime.Serialization[0xd1e21520] -> mscorlib[0xf1c41ae0]: 51
Loaded assembly: System.Runtime.Serialization.dll [External]
09-30 18:58:20.320 D/Mono ( 7470): Loading reference 8 of /storage/emulated/0/Android/data/com.YourCompany.WorkingWithImages/files/.override/Xamarin.Forms.Platform.Android.dll asmctx DEFAULT, looking for Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
09-30 18:58:20.320 D/Mono ( 7470): Assembly Ref addref Xamarin.Forms.Platform.Android[0xf1c43940] -> Xamarin.Android.Support.Compat[0xf1c42500]: 5
09-30 18:58:20.321 D/Mono ( 7470): Loading reference 2 of /storage/emulated/0/Android/data/com.YourCompany.WorkingWithImages/files/.override/Xamarin.Android.Support.Compat.dll asmctx DEFAULT, looking for Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065
09-30 18:58:20.321 D/Mono ( 7470): Assembly Ref addref Xamarin.Android.Support.Compat[0xf1c42500] -> Java.Interop[0xf1c43be0]: 10
[HotReload] (2019-09-30 18:58:17.0): INFO: HotReload: Initialized Agent.
[HotReload] (2019-09-30 18:58:21.1): INFO: Hot Reload Connected and Ready.
09-30 18:58:20.390 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:20.390 D/Mono ( 7470): Searching for 'java_interop_jnienv_call_nonvirtual_boolean_method_a'.
09-30 18:58:20.390 D/Mono ( 7470): Probing 'java_interop_jnienv_call_nonvirtual_boolean_method_a'.
09-30 18:58:20.390 D/Mono ( 7470): Found as 'java_interop_jnienv_call_nonvirtual_boolean_method_a'.
09-30 18:58:20.435 D/OpenGLRenderer( 7470): Skia GL Pipeline
09-30 18:58:20.544 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:20.544 D/Mono ( 7470): Searching for 'java_interop_jnienv_call_nonvirtual_int_method_a'.
09-30 18:58:20.544 D/Mono ( 7470): Probing 'java_interop_jnienv_call_nonvirtual_int_method_a'.
09-30 18:58:20.544 D/Mono ( 7470): Found as 'java_interop_jnienv_call_nonvirtual_int_method_a'.
09-30 18:58:20.580 D/ ( 7470): HostConnection::get() New Host Connection established 0xd155a5c0, tid 7508
09-30 18:58:20.587 I/ConfigStore( 7470): android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
09-30 18:58:20.587 I/ConfigStore( 7470): android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
09-30 18:58:20.587 I/OpenGLRenderer( 7470): Initialized EGL, version 1.4
09-30 18:58:20.587 D/OpenGLRenderer( 7470): Swap behavior 1
09-30 18:58:20.588 W/OpenGLRenderer( 7470): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
09-30 18:58:20.588 D/OpenGLRenderer( 7470): Swap behavior 0
09-30 18:58:20.608 D/EGL_emulation( 7470): eglCreateContext: 0xd24eeca0: maj 3 min 0 rcv 3
09-30 18:58:20.669 D/EGL_emulation( 7470): eglMakeCurrent: 0xd24eeca0: ver 3 0 (tinfo 0xd241a400)
09-30 18:58:20.795 D/Mono ( 7470): Loading reference 7 of /storage/emulated/0/Android/data/com.YourCompany.WorkingWithImages/files/.override/Xamarin.Android.Support.Fragment.dll asmctx DEFAULT, looking for Xamarin.Android.Arch.Lifecycle.LiveData.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
09-30 18:58:20.795 D/Mono ( 7470): Assembly Ref addref Xamarin.Android.Support.Fragment[0xf1c42c80] -> Xamarin.Android.Arch.Lifecycle.LiveData.Core[0xf1c41f00]: 2
09-30 18:58:21.146 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:21.146 D/Mono ( 7470): Searching for 'java_interop_jnienv_call_nonvirtual_float_method_a'.
09-30 18:58:21.146 D/Mono ( 7470): Probing 'java_interop_jnienv_call_nonvirtual_float_method_a'.
09-30 18:58:21.146 D/Mono ( 7470): Found as 'java_interop_jnienv_call_nonvirtual_float_method_a'.
09-30 18:58:21.276 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:21.276 D/Mono ( 7470): Searching for 'java_interop_jnienv_get_static_object_field'.
09-30 18:58:21.276 D/Mono ( 7470): Probing 'java_interop_jnienv_get_static_object_field'.
09-30 18:58:21.276 D/Mono ( 7470): Found as 'java_interop_jnienv_get_static_object_field'.
09-30 18:58:21.635 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:21.636 D/Mono ( 7470): Searching for 'java_interop_jnienv_is_assignable_from'.
09-30 18:58:21.636 D/Mono ( 7470): Probing 'java_interop_jnienv_is_assignable_from'.
09-30 18:58:21.636 D/Mono ( 7470): Found as 'java_interop_jnienv_is_assignable_from'.
09-30 18:58:21.641 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:21.641 D/Mono ( 7470): Searching for 'java_interop_jnienv_get_byte_array_region'.
09-30 18:58:21.641 D/Mono ( 7470): Probing 'java_interop_jnienv_get_byte_array_region'.
09-30 18:58:21.641 D/Mono ( 7470): Found as 'java_interop_jnienv_get_byte_array_region'.
09-30 18:58:21.649 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:21.649 D/Mono ( 7470): Searching for 'java_interop_jnienv_set_byte_array_region'.
09-30 18:58:21.649 D/Mono ( 7470): Probing 'java_interop_jnienv_set_byte_array_region'.
09-30 18:58:21.649 D/Mono ( 7470): Found as 'java_interop_jnienv_set_byte_array_region'.
09-30 18:58:21.652 D/skia ( 7470): --- Failed to create image decoder with message 'unimplemented'
[0:] ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri: https://aka.ms/campus.jpg
Thread started: #7
09-30 18:58:21.888 D/EGL_emulation( 7470): eglMakeCurrent: 0xd24eeca0: ver 3 0 (tinfo 0xd241a400)
09-30 18:58:22.001 D/skia ( 7470): --- Failed to create image decoder with message 'unimplemented'
[0:] ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri: https://aka.ms/campus.jpg
09-30 18:58:26.211 D/Mono ( 7470): DllImport searching in: '__Internal' ('(null)').
09-30 18:58:26.211 D/Mono ( 7470): Searching for 'java_interop_jnienv_call_float_method_a'.
09-30 18:58:26.211 D/Mono ( 7470): Probing 'java_interop_jnienv_call_float_method_a'.
09-30 18:58:26.211 D/Mono ( 7470): Found as 'java_interop_jnienv_call_float_method_a'.

@ddo88
Copy link

ddo88 commented Sep 30, 2019

same problem here

@PureWeen
Copy link
Contributor

@ddo88 @developer9969 I realize this one is as simple as downloaded that sample :-) But can you zip up your projects anyway and attach just so I can verify

@PureWeen
Copy link
Contributor

@ddo88 @developer9969 can you also

  • make sure all your android sdk tools are updated?
  • factory reset the simulator device
  • if you're releases to a physical device uninstall the app and mono shared runtime
  • test with a release build?

@developer9969
Copy link
Author

developer9969 commented Sep 30, 2019

@PureWeen Hi good news! I have done a factory reset on the simulator device and works with the latest stable. I cannot try the device as I need to be connected to the machine at work.
I should have done it before I usually do once a day..Sorry for wasting your time!.

Now I will have the issue of how to build using the android 28.0.0.3 on those azure pipelines all those agents are outdated and crashes the build. grrr.

@GeordieStew
Copy link

Nightly build not working for me either

@tefaabdellatief
Copy link

tefaabdellatief commented Sep 30, 2019

same issue here using xamarin.forms 4.2.0.778463, but with the latest version of xamarin forms 4.2.0.815419 and android support 28.0.0.3, it's working fine

@AndreAbrantes
Copy link

@PureWeen Hello, Shane!
After the update for the lastest prerelease 4.3.0.819712-pre2, do the factory reset, uninstalled the last version and tested with the release build. It's working fine!
I did the same test in a Pixel 3 and works well.
For these tests, I've used the Xaminals sample.
Thank you!

@PureWeen
Copy link
Contributor

PureWeen commented Oct 1, 2019

For anyone else running into this issue can you try any of the following

  • just uninstall the app
  • turn caching off on the URIImageSource (there's a bug where if it was retrieved wrong in the previous version it'll return the wrong cached version in the new one)

@PureWeen PureWeen removed s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/unverified New report that has yet to be verified labels Oct 2, 2019
@theo-albers
Copy link

theo-albers commented Oct 4, 2019

I'm having this issue as well. I upgraded from XF4.1 to 4.2 latest and got "System.ArgumentException: An element with the same key already exists in NameScope Parameter name: name" on various forms. Downgrading to XF4.1 solved that issue, but I couldn't get rid of the image problem.
The image not showing problem changed from Factory being null in 4.2 to stream closed in 4.1. I upgraded to VS2019 16.3 this week.

@theo-albers
Copy link

With 4.1.0.673156 I get this with VS2019, 16.3.1:

10-04 20:53:28.492 D/skia (12559): --- SkAndroidCodec::NewFromStream returned null
[0:] ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri: https://****

Of course the url was not ****, but a valid url which has access to a jpeg image. With 4.1.778454 I get the stream closed exception. With 4.2.848062 I also get no picture. When I do a direct HttpClient.Get in that same Xamarin Page, the picture will be downloaded properly. It just doesn't work via XAML markup. I'm stuck because of the other NameScope issue as well.

@PureWeen
Copy link
Contributor

PureWeen commented Oct 4, 2019

#7751 (comment)

#7764

@theo-albers
Copy link

theo-albers commented Oct 4, 2019

I see that the Android GetStreamAsync in https://github.com/xamarin/Xamarin.Forms/blob/151bdb5ebfd0cfbcad0aa10d6327ff79e534fda5/Xamarin.Forms.Platform.Android/Forms.cs is newing up an HttpClient for every image:

public async Task<Stream> GetStreamAsync(Uri uri, CancellationToken cancellationToken)
{
	using (var client = new HttpClient())				
	{
		HttpResponseMessage response = await client.GetAsync(uri, cancellationToken).ConfigureAwait(false);
		if (!response.IsSuccessStatusCode)
		{
			Internals.Log.Warning("HTTP Request", $"Could not retrieve {uri}, status code {response.StatusCode}");
			return null;
		}

		// the HttpResponseMessage needs to be disposed of after the calling code is done with the stream 
		// otherwise the stream may get disposed before the caller can use it
		return new StreamWrapper(await response.Content.ReadAsStreamAsync().ConfigureAwait(false), response);					
	}
}

As far as I know disposing HttpClient results in unreliable behavior. See also https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests.

@theo-albers
Copy link

#7751 (comment)

#7764

I did uninstall the app, uninstalled the runtime as well. No luck.

@jhadz81
Copy link

jhadz81 commented Dec 2, 2019

Workaround that @REDECODE suggested to use Visual Studio 2017 worked for me. Hours and hours wasted on this and it is not feasible for me to upgrade to Xamarin Forms 4 to get this bug fix as I am on Xamarin Forms 3.6.0.639721. Would be nice for this to get fixed in Xamarin Forms 3.6 and VS 2019.

@PureWeen
Copy link
Contributor

PureWeen commented Dec 2, 2019

@jhadz81

it is not feasible for me to upgrade to Xamarin Forms 4

Why?

Would be nice for this to get fixed in Xamarin Forms 3.6 and VS 2019.

Are you on the latest version of VS 2019? I was thinking they fixed this in the latest release of Mono

@jhadz81
Copy link

jhadz81 commented Dec 2, 2019

Why?

Because I have a bunch of dependencies on NuGet packages that have not been upgraded to support Forms 4 and the client isn't going to pay me to rip out Forms 3, replace it with Forms 4, and find alternates to those packages that work with 4. Plus there is no reason that this shouldn't work in Forms 3. Not Forms 3 it old and unsupported.

I am on 16.3.7 and it looks like .10 is out. I'll try updating. Thanks.

@PureWeen
Copy link
Contributor

PureWeen commented Dec 2, 2019

Because I have a bunch of dependencies on NuGet packages that have not been upgraded to support Forms 4

What packages? We don't really use semantic versioning. The 3 to 4 doesn't really mean that it's breaking and all related packages have to also be on 4.

For the most part any packages you have compiled for 3 should work for 4.

If just updating to the latest XF 4 totally breaks your application then I would be curious as to why because it might be something we need to fix.

Ideally your upgrade from v3 to v4 should be seamless

@bondarenkod
Copy link
Contributor

bondarenkod commented May 12, 2020

The bug is presented only for some image URLs:
[OK]: https://bdfss.blob.core.windows.net/shots/msedge_12_05_2020__17_20_58__ca81e3fa-0e7a-4562-b12e-2eb592c164a4.png
headers:

HTTP/1.1 200 OK
Content-Length: 78362
Content-Type: image/png
Content-MD5: bhmBjBhnKmixHtvrcPzJzw==
Last-Modified: Tue, 12 May 2020 14:20:58 GMT
Accept-Ranges: bytes
ETag: "0x8D7F67FB0A0A14A"
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: 15163051-001e-0130-3668-28ddcc000000
x-ms-version: 2014-02-14
x-ms-lease-status: unlocked
x-ms-lease-state: available
x-ms-blob-type: BlockBlob
Date: Tue, 12 May 2020 14:23:56 GMT

[Error]: https://via.placeholder.com/200.png?text=hello_world
headers:

HTTP/1.1 200 OK
Server: nginx/1.6.2
Date: Tue, 12 May 2020 14:23:23 GMT
Content-Type: image/png
Content-Length: 438
Connection: keep-alive
Last-Modified: Tue, 12 May 2020 14:23:00 GMT
ETag: "5ebab144-1b6"
Accept-Ranges: bytes
Expires: Wed, 13 May 2020 14:23:23 GMT
Cache-Control: max-age=86400
X-Cache: L2

The error text is:

[0:] HTTP Request: Could not retrieve https://via.placeholder.com/200.png?text=hello_world, status code Gone
[0:] ImageLoaderSourceHandler: Could not retrieve image or image data was invalid: Uri: https://via.placeholder.com/200.png?text=hello_world

image

Xamarin.Forms - 4.6.0.726

The demo XFIMAG.zip

@fakhravari
Copy link

@silasas
Copy link

silasas commented Aug 13, 2020

I am in trouble to load images.
Some images work, but others not.

I think is firewall or other thing in the remote server. it is blocking the connection...

@serbesthamit
Copy link

Goto Android Project, then click on properties,
click on assemblyinfo.cs
[assembly: Application(UsesCleartextTraffic = true)]

https://forums.xamarin.com/discussion/164771/cleartext-http-traffic-not-permitted

@alexrasquinho
Copy link

Goto Android Project, then click on properties,
click on assemblyinfo.cs
[assembly: Application(UsesCleartextTraffic = true)]

https://forums.xamarin.com/discussion/164771/cleartext-http-traffic-not-permitted

thank you very very very much !! simple solution... work for me!!

@winkmichael
Copy link

Goto Android Project, then click on properties, click on assemblyinfo.cs [assembly: Application(UsesCleartextTraffic = true)]

https://forums.xamarin.com/discussion/164771/cleartext-http-traffic-not-permitted

Thanks, this fixes it for HTTPS sites, however HTTPS still seems problematic, and there appears to be no way to ignore an invalid certificate.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests