Bug 23365 - Image fails loading from long URL
Summary: Image fails loading from long URL
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.3
Hardware: PC Windows
: High major
Target Milestone: ---
Assignee: Jason Smith [MSFT]
Depends on:
Reported: 2014-09-25 07:57 UTC by Klaus Krapfenbauer
Modified: 2015-01-22 12:54 UTC (History)
12 users (show)

Is this bug a regression?: ---
Last known good build:

Proof of concept (116.82 KB, application/octet-stream)
2014-10-03 03:28 UTC, Klaus Krapfenbauer

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 Klaus Krapfenbauer 2014-09-25 07:57:03 UTC
When using an Image view with the Source property set to a URL with >=238 characters, it simply doesn't load the image. Since I am only developing on Android by now consider the bug to be confirmed only on Android although it might occur on other platforms too.

Proof of concept:

Place the following Image in an arbitrary Xamarin.Forms XAML page:

<Image Source="http://imgs.xkcd.com/comics/tasks.png?a=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" />

The URL is a comic from XKCD.com with a query parameter to pad the length of the URL. The URL string is exactly 238 characters long. The image will not load with this version of the Image tag, if you shorten the URL to 237 characters by removing one "b", the image will load.
Comment 1 Klaus Krapfenbauer 2014-09-25 08:00:22 UTC
@the maintainers of this database:

I made the bug entry private by accident. Please make it public so others can see it too.
Comment 2 Klaus Krapfenbauer 2014-10-03 03:13:26 UTC
Seems like with the newest version of Xamarin ( the maximum length for a URL changed from 237 to 241. So now images with a URI length of <= 241 are working and images with a URI length >= 242 are not working.

In addition to the little code snippet I will upload a POC solution.
Comment 3 Klaus Krapfenbauer 2014-10-03 03:14:36 UTC
Additional info:
I tested everything with a Google LGE Nexus 5 on Android 4.4.4.
Comment 4 Klaus Krapfenbauer 2014-10-03 03:28:39 UTC
Created attachment 8296 [details]
Proof of concept

Proof of concept for bug #23365 with Xamarin.Forms
Comment 5 Jon Goldberger [MSFT] 2014-12-04 15:16:15 UTC
Investigating this issue, which is also discussed on a forum thread [1], I can confirm that this occurs on iOS as well. The forum thread mentions that this happens when binding, but the issue does not seem to depend on binding. I get the same error as noted in the forum thread only when deploying to an iOS simulator. On an Android simulator, I get no exception and the app does not crash but the image does not show as noted in the bug description. The iOS app throws the following exception:

>System.IO.PathTooLongException: Path is too long. Path: http%3A%2F%2Fimgs.xkcd.com%2Fcomics%2Ftasks.png%3Fa%3Dbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

and the app crashes. 

The workaround noted in the forum thread, to use a UriImageSource and turn off caching, does _not_ resolve the issue on iOS, but does on Android. 

The workaround as noted is:

> new Image { Source= new UriImageSource(){ 
>     Uri = new Uri(
>          "http://imgs.xkcd.com/comics/tasks.png?a=bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
>    CachingEnabled = false } 

Tested the above using Visual Studio 2013 and Forms version 1.2.3

However in Xamarin Studio the workaround _does_ resolve the issue on iOS. 

[1] https://forums.xamarin.com/discussion/22044/exception-with-long-image-uris

### Visual Studio Version info:

Microsoft Visual Studio Ultimate 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Ultimate

Architecture and Modeling Tools   06181-004-0451031-02209
Microsoft Architecture and Modeling Tools
UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.

LightSwitch for Visual Studio 2013   06181-004-0451031-02209
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06181-004-0451031-02209
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06181-004-0451031-02209
Microsoft Visual Basic 2013

Visual C# 2013   06181-004-0451031-02209
Microsoft Visual C# 2013

Visual C++ 2013   06181-004-0451031-02209
Microsoft Visual C++ 2013

Visual F# 2013   06181-004-0451031-02209
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06181-004-0451031-02209
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06181-004-0451031-02209
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.3.50717.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.20703.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.2
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone

Microsoft Azure Mobile Services Tools   1.2
Microsoft Azure Mobile Services Tools

Microsoft Azure Tools   2.4
Microsoft Azure Tools for Microsoft Visual Studio 2013 - v2.4.20730.1601

NuGet Package Manager   2.8.50313.46
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.2
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SAPReferenceManager   1.0
Manages References to Shared Projects

SQL Server Data Tools   12.0.40706.0
Microsoft SQL Server Data Tools

Windows Azure Tools   2.3
Windows Azure Tools for Microsoft Visual Studio 2013 - v2.3.20320.1602

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin (10cfd178d55287f09c85f5a1e604dfe20889a40f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android (ba9bbbdd44cfdc4bf485e8885bd2ad24fba525f7)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS (840a925103a0bf4a856507f13d5eaee3c1579c2f)
Visual Studio extension to enable development for Xamarin.iOS.

### Xamarin Studio Version info:

=== Xamarin Studio ===

Version 5.5.4 (build 15)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
	Mono 3.10.0 ((detached/92c4884)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000031

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.2    (API level 8)
		2.3    (API level 10)
		3.0    (API level 11)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 840a925
Build date: 2014-11-16 21:03:22-0500

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 15:32:41-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8

=== Operating System ===

Mac OS X 10.10.1
Darwin Jons-iMac.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 8 Jon Goldberger [MSFT] 2014-12-04 15:18:57 UTC
Changed importance from Blocker to Major as blocker is meant to indicate that this is going to block a release for Xamarin.
Comment 9 Jon Goldberger [MSFT] 2014-12-04 15:29:58 UTC
The customer mentioned in private comment 6 asks if this may be possible:

"would you consider unsealing the class and changing the GetCacheKey to a non-static virtual method that we could override?"
Comment 10 Shawn 2014-12-10 21:08:30 UTC
Any updates
Comment 11 Oren Novotny 2015-01-07 10:50:07 UTC
Why is UriImageSource even keeping a local cache? Isn't that the OS's job?

On WP8, it'll cache the remote image anyway:

If you do want extra control over a cache, then it can be done via a ValueConverter:

Also, as per that cache, he uses a sha1 sig of the Url as the cache key as that'll be short and unique instead of using the whole path.

What we really need is a "pass through" that lets us use the OS's "Bind to URL" functionality instead of something that's adding a cache. Having something that does extra caching is fine too, but it shouldn't be the default or only option.
Comment 12 Rui Marinho 2015-01-12 13:24:25 UTC
*** Bug 25909 has been marked as a duplicate of this bug. ***
Comment 13 Rui Marinho 2015-01-13 07:44:03 UTC
Fixed in the next release 1.3.2
Comment 14 Oren Novotny 2015-01-13 07:53:12 UTC

How was the fix made? Was there any thought to removing the local cache (or providing an alternate UriImageSource implementation that does not cache by itself and falls-back to the OS caching?
Comment 15 Rui Marinho 2015-01-13 08:01:38 UTC
Hi Oren 

We have fixed the reported bug of the crash of using long url.
You are able to set XF caching off if you want:

Hope this helps.

Comment 16 Oren Novotny 2015-01-13 08:05:03 UTC
Caching enabled is one thing, but how about dealing with displaying images off the web w/o blowing the devices memory?

Something like this:

On WP8 you can set the DecodePixelHeight, DecodePixelWidth. Without them, OOM exceptions frequently occur when loading a list view of images.

There are a few gotcha's with WP8 BitmapImages and the code in the gist is designed to work with them.

I can also submit this to the labs, but having more robust image support "built-in" is essential.
Comment 17 Shawn 2015-01-13 08:17:36 UTC
I completely agree with this -- I was seriously impressed that loading 10 to 20 images completely wiped out memory in the emulator.
Comment 18 Rui Marinho 2015-01-13 08:21:27 UTC
Oren please open a new issue related with that subject, please provide a test case so the team can look at it.

Comment 19 Oren Novotny 2015-01-13 10:15:24 UTC

I already had a ticket open and I've added a full repro:
Comment 20 Rajneesh Kumar 2015-01-22 12:54:55 UTC
I have checked this issue with the following builds:

Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.50938
Xamarin (d6a2cae)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
Xamarin.Android (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.

Now this issue is working fine, to verify this issue I have use the attached test case and I observed that images with long URL loads successfully. Here is the screencast for the same: http://www.screencast.com/t/0ATSSNbArY44

This issue has been fixed, hence closing this issue.