Bug 51173 - ImageRenderer, async void SetImage - Cannot catch exceptions
Summary: ImageRenderer, async void SetImage - Cannot catch exceptions
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-01-02 15:54 UTC by François M
Modified: 2017-07-12 12:26 UTC (History)
7 users (show)

Tags: iOS ac
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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description François M 2017-01-02 15:54:17 UTC
As SetImage is async void and not awaited, if it trows an error it cannot be caught and the app crashes.

Comment 1 adrianknight89 2017-02-25 00:55:34 UTC
If you do a quick search for "async void", you'll see that XF has this issue in many places (ignoring event handlers). Fixing them all will cause certain methods to be async even though they are not meant to be.

For example, how would one handle GetCell() of iOS ImageCellRenderer?

Also, SetImage() is handling TaskCanceledException so the user doesn't have to worry about it, but it wouldn't handle other types of exceptions. Since we're trying to load an image, I'm wondering if it makes sense to catch all exceptions and set uiimage = null;.

What kind of error did you run into that crashed your app?
Comment 2 François M 2017-02-28 10:57:40 UTC
I wanted to catch error from LoadAsync which is called by SetImage.
Since then, I found out I can do ExportImageSourceHandler and then implement my own LoadAsync.
Comment 3 E.Z. Hart [MSFT] 2017-03-30 22:43:47 UTC
PR: https://github.com/xamarin/Xamarin.Forms/pull/849
Comment 4 Rui Marinho 2017-04-25 18:17:43 UTC
Should be fixed on 2.3.6-pre1
Comment 5 Neha Kharbade 2017-07-04 07:15:49 UTC
Hi Rui,

Can you please help me for verifying the fix being applied in above bug. Any Steps to reproduce the bug would be great.

Thanks in advance.
Comment 6 E.Z. Hart [MSFT] 2017-07-08 01:09:46 UTC
(In reply to Neha Kharbade from comment #5)
> Hi Rui,
> Can you please help me for verifying the fix being applied in above bug. Any
> Steps to reproduce the bug would be great.
> Thanks in advance.

If you run the ControlGallery application, you can look at the test for issue 51173 and verify it using the instructions there.
Comment 7 Saurabh Paunikar 2017-07-12 12:26:01 UTC
Verified on xamarin.form version

I downloaded Xamarin.form master sample and run ControlGallery on android, iOS and UWP app. And followed the instruction given for test B51173. 

ScreenCast link : https://www.screencast.com/t/2GrP9QXLio