Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 23163 [details]
I am facing "System.Threading.Tasks.TaskCanceledException: A task was canceled." exception while update the BindingContaxt at runtime in Xamarin Forms iOS. I have ContentView with image as content of it. I have updating the BindingContaxt at runtime. I have attached the sample here.
1. Enable the Common Language Runtime Exceptions setting.
2. Run the attached sample.
3. Update the BindingContaxt by clicking the button "Update BindingContaxt"
4. Now the crash will be occurred.
1. Visual Studio Professional 2015 with Update 2.
2. iPod device(OS - 10.1.1(14B100), Model - MKH62BT/A)
The above reported issue reproduced in Xamarin Forms UWP also. Can you please check and revert us.
I ran the project provided in Visual Studio with all CLR Exceptions enabled and I was able to see the TaskCanceledException get thrown. However I was also able to continue the app's execution and observe that it did not crash. Likewise, debugging the app with the default CLR exceptions enabled did not cause the app to crash.
According to the stack trace the exception is being thrown here due to the CancellationTokenSource. Looking at your Button click handling code, the BindingContext of the ContentView changes several times in the foreach loop. Since the Image Source loads a new stream each time the BindingContext changes, it cancels any previous operation and throws the exception.
You can prevent this by avoiding rapid changes to the Image Source. Regardless, we do catch the exception in this case as well so this shouldn't crash the app even if it does occur. Hope this helps!