Bug 36095 - Uri is longer than the maximum 32766 characters
Summary: Uri is longer than the maximum 32766 characters
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2015-11-20 09:16 UTC by John Miller [MSFT]
Modified: 2015-11-23 08:00 UTC (History)
5 users (show)

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

Sample Project (1.29 MB, application/zip)
2015-11-20 09:16 UTC, John Miller [MSFT]

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 GitHub or Developer Community 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 John Miller [MSFT] 2015-11-20 09:16:48 UTC
Created attachment 13914 [details]
Sample Project


   FormUrlEncodedContent throws an exception when the key/value pair is large. 

**Steps to Reproduce:**

   1. Run the attached sample on an iOS simulator

**Actual Results:**

   System.UriFormatException: Uri is longer than the maximum 32766 characters.
  at System.Uri.EscapeDataString (System.String stringToEscape) [0x00021] in /Users/builder/data/lanes/2356/3c0ec355/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System/Uri.cs:1829 
  at System.Net.Http.FormUrlEncodedContent.SerializeValue (System.String value) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 
  at System.Net.Http.FormUrlEncodedContent.EncodeContent (IEnumerable`1 nameValueCollection) [0x0005f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 
  at System.Net.Http.FormUrlEncodedContent..ctor (IEnumerable`1 nameValueCollection) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/ 
  at test_uri_error.WebServices.UploadPhotoToServerUsingHttpClient (test_uri_error.PhotoClass pc) [0x00046] in /Users/joe/Projects/Learning/test_uri_error/test_uri_error/WebServices.cs:31 
  at test_uri_error.AppDelegate.FinishedLaunching (UIKit.UIApplication application, Foundation.NSDictionary launchOptions) [0x0005f] in /Users/joe/Projects/Learning/test_uri_error/test_uri_error/AppDelegate.cs:39 
  at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2356/3c0ec355/source/maccore/src/UIKit/UIApplication.cs:77 
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/2356/3c0ec355/source/maccore/src/UIKit/UIApplication.cs:61 
  at test_uri_error.Application.Main (System.String[] args) [0x00008] in /Users/joe/Projects/Learning/test_uri_error/test_uri_error/Main.cs:12 

**Expected Results:**

   Max character limit is expected to be 65536 for .Net 4.5+

**Build Date & Platform:**

=== Xamarin Studio ===

Version 5.10 (build 871)
Installation UUID: e01c3049-a2d2-4e0a-aad8-afe6fb627c4d
	Mono 4.2.1 (explicit/6dd2d0d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010102

=== Xamarin.Profiler ===

Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 7.1 (9079)
Build 7B91b

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 3c0ec35
Branch: master
Build date: 2015-11-12 13:05:39-0500

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/johnmiller/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

=== Xamarin Android Player ===

Version: 0.6.2
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 510000871
Git revision: 4e9c5abb5ffdae12ba02ac49da83f8b2011dbb88
Build date: 2015-11-12 06:02:54-05
Xamarin addins: 55007ed0e56436f385d8e26394a45be563abc7e8
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.10.5

**Additional Information:**

   I can't seem to find the documentation supporting the new upper limit. 
   Similar issue was filed for RestSharp supporting that: https://github.com/FubarDevelopment/restsharp.portable/issues/12
   MSDN shows a 32766 limit for EscapeDataString: https://msdn.microsoft.com/en-us/library/system.uri.escapedatastring(v=vs.110).aspx
Comment 1 Marek Safar 2015-11-21 04:49:53 UTC
Fixed in master (bumped he limit)
Comment 2 Joseph Hanna 2015-11-22 05:24:58 UTC
Thanks for your prompt action Marek.  What is the new limit? We are uploading files that are multiple megabytes.
Comment 3 Marek Safar 2015-11-22 06:19:13 UTC
The limit is same as .net (0xFFF0). I am not sure why for multi megabytes files you need such long uri
Comment 4 Joseph Hanna 2015-11-22 14:01:12 UTC
Hi Marek

As per my sample, the issue is related to the encoded Form contents when POSTing, not the uri as the error message suggests. 

Comment 5 Marek Safar 2015-11-23 08:00:48 UTC
That's by design limitation of FormUrlEncodedContent. If you need to send large data looks for System.Net.Http.HttpContent implementation which suites you best.