Bug 37022 - [UWP] crash from cached image uriimagesource
Summary: [UWP] crash from cached image uriimagesource
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.0.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Samantha Houts [MSFT]
URL: Assigned to you as you were last to r...
Depends on:
Blocks:
 
Reported: 2015-12-15 15:54 UTC by Jorrit
Modified: 2017-09-07 03:38 UTC (History)
14 users (show)

Tags: ac, uwp, image, norepro, retest
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 37022 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Jorrit 2015-12-15 15:54:23 UTC
When binding a listview with an image bound to an online imageesourceuri, after scrolling about 50 rows, the app crashes with below exception.

System.Exception: The component cannot be found. (Exception from HRESULT: 0x88982F50)
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Xamarin.Forms.Platform.WinRT.ImageLoaderSourceHandler.<LoadImageAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Xamarin.Forms.Platform.WinRT.ImageRenderer.<UpdateSource>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(Object state)
   at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
The program '[3860] [appname].Forms.WinPhone81.exe' has exited with code 0 (0x0).
Comment 1 Jorrit 2015-12-15 16:20:33 UTC
Besides the "The component cannot be found", sometimes the crash is caused by a Nullreference. It comes from the same source:

---
System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at Xamarin.Forms.Platform.WinRT.ImageLoaderSourceHandler.<LoadImageAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Xamarin.Forms.Platform.WinRT.ImageRenderer.<UpdateSource>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__3(Object state)
   at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()
The program '[1696] [appname].Forms.WinPhone81.exe' has exited with code 0 (0x0).
Comment 2 Jorrit 2015-12-15 19:10:51 UTC
I tracked this down to the following:

- It has nothing to do with the listview, but the problem comes from the image renderer, and it happens with a cached image that is already loaded before.
- In my case, the exception came from one specific image in the listview. If I skip this image, everything loads fine.
- So I skipped the Listview loading (just leaving it empty) and added a simple Image with Source = [the failing url] to my page. This one image also makes the app crash. If I load a different image, it runs fine.
- Then, if I add something to this url querystring to make it unique, the image loads fine. Something like '?a=b'. So it has nothing to to with being a 'invalid' or non-existing image or something like that.

- After this, I created a custom image renderer in WP and used this to disable uriimagesource caching on WP.
- Finally, everything loads fine and the listview keeps working very stable.

Off course, I'm very sad having to disable the caching because the caching really speeds up things.
Comment 3 Chris King 2016-12-21 23:04:20 UTC
Jorrit, sorry to hear you're having this issue; thanks for reporting this. If you're still blocked by this issue would you be willing to provide the reproduction you created using the latest version of XF? Issues with reduced reproductions are given priority during triage.

Warm regards,
XFT
Comment 4 David Waterman 2017-03-24 12:55:13 UTC
There is a race condition in the WinRT ImageRenderer:
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.WinRT/ImageRenderer.cs

In UpdateSource At line 146/147, the comment "some zippy little app might have disposed of this Image already" shows that someone made a stab at fixing the race condition by adding a null check for the Control property.
Unfortunately they forgot to add the null check to UpdateAspect which will be called at line 49 straight after UpdateSource returns.
This leads to a NRE in UpdateAspect if the Image view is removed from the page  (Control set to null) before the image is loaded; e.g. in a zippy little app.

I suspect this is the problem that Jorrit was observing.

I am seeing the problem in an app that adds and removes images as the user scrolls the page; when scrolled fast the app may crash with an NRE in the UWP ImageRenderer.
Comment 5 Chris King 2017-06-19 17:08:46 UTC
Assigned to you as you were last to requeste info for this bug.
Comment 6 Samantha Houts [MSFT] 2017-06-19 21:01:21 UTC
Confirming this issue. Thank you!
Comment 7 Ant Klad 2017-07-17 09:22:10 UTC
I have the same problem :
{System.NullReferenceException: Object reference not set to an instance of an object.
   at Xamarin.Forms.Platform.UWP.ImageRenderer.UpdateAspect()
   at Xamarin.Forms.Platform.UWP.ImageRenderer.<OnElementChanged>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
   at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()}

My app is working perfectly on Android and iOS but I can't publish it for Windows due to this bug.

Is there a schedule for its fix?
Comment 8 Ant Klad 2017-07-17 11:18:51 UTC
Also I would like to add that the bug only occurs when I use ImageSource.FromResource but not when I use ImageSource.FromFile.
Comment 9 Christian Schwarz 2017-08-22 16:44:09 UTC
I am also affected by this issue (NullReferenceException in ImageRenderer.UpdateAspect()). Hoping for a fix in 2.4.0.
Comment 10 predalpha 2017-08-25 13:42:08 UTC
Facing this issue too in my UWP app when i press desktop backbutton while my images (source from web uri) arent fully loaded.
Comment 11 predalpha 2017-08-25 15:07:25 UTC
seems that my issue is solved with 2.4.0.266-pre1