Bug 51321 - WinRT FileImageSourceHandler doesn't work
Summary: WinRT FileImageSourceHandler doesn't work
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.3.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
Depends on:
Reported: 2017-01-10 09:35 UTC by François M
Modified: 2017-06-15 16:38 UTC (History)
2 users (show)

Tags: uwp
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-10 09:35:30 UTC
On WP 8.1, I couldn't display images from files (downloaded from Azure Storage). I got E_NETWORK_ERROR. Surely something to do with file location.
To make it work, I had to replace the call to that method
with the part of that renderer about files:

Which gives the below method (which only works with FileImageSource as this is what I need right now):

async Task UpdateSource()

            var source = Element.Source;
            if (source != null)
                Windows.UI.Xaml.Media.ImageSource imagesource = null;

                    var fi = Element.Source as FileImageSource;
                    var myFile = Path.Combine(Package.Current.InstalledLocation.Path, fi.File);
                    var myFolder = await StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(myFile));
                    using (var s = await myFolder.OpenStreamForReadAsync(Path.GetFileName(myFile)))
                        var memStream = new MemoryStream();
                        await s.CopyToAsync(memStream);
                        memStream.Position = 0;
                        var bitmapImage = new BitmapImage();
                        imagesource = bitmapImage;
                catch (OperationCanceledException)
                    imagesource = null;
                catch (Exception ex)
                    Debug.WriteLine($"Error updating image source: {ex}");

                // In the time it takes to await the imagesource, some zippy little app
                // might have disposed of this Image already.
                if (Control != null)
                    Control.Source = imagesource;

                Control.Source = null;
Comment 1 Paul DiPietro [MSFT] 2017-03-27 23:43:51 UTC
Out of curiosity, do you have a reproduction project sampling what you're attempting to do so we can see the error in action?
Comment 2 François M 2017-04-19 14:17:28 UTC
No repro sorry.
And I gave up on Win 8.1 anyway.
Comment 3 Paul DiPietro [MSFT] 2017-06-15 16:38:23 UTC
Closing this. If this is an issue on UWP using the latest prerelease and/or nightly build, please reopen with a minimized reproduction project.