Bug 51321 - WinRT FileImageSourceHandler doesn't work
Summary: WinRT FileImageSourceHandler doesn't work
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.3.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
URL:
Depends on:
Blocks:
 
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:
Status:
RESOLVED NOT_REPRODUCIBLE

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
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.WinRT/FileImageSourceHandler.cs#L14
in
https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Platform.WinRT/ImageRenderer.cs#L123
with the part of that renderer about files:
https://github.com/bitdisaster/Hanselman.Forms/commit/4eb31e3ffe6e2e2a9f0d8eb7eee408748882a1f3

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

async Task UpdateSource()
        {
            ((IImageController)Element).SetIsLoading(true);

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

                try
                {
                    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();
                        bitmapImage.SetSource(memStream.AsRandomAccessStream());
                        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;
                }

                RefreshImage();
            }
            else
            {
                Control.Source = null;
                ((IImageController)Element)?.SetIsLoading(false);
            }
        }
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.