Bug 18422 - HttpClient doesn't support 'name[]' header field name format
Summary: HttpClient doesn't support 'name[]' header field name format
Alias: None
Product: Class Libraries
Classification: Mono
Component: General ()
Version: 3.2.x
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
Depends on:
Reported: 2014-03-17 09:44 UTC by Grigory (Playtika)
Modified: 2014-11-27 06:44 UTC (History)
4 users (show)

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 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 Grigory (Playtika) 2014-03-17 09:44:42 UTC
{System.FormatException: Invalid format.
  at System.Net.Http.Headers.NameValueHeaderValue.set_Value (System.String value) [0x00000] in <filename unknown>:0 
  at System.Net.Http.Headers.NameValueHeaderValue..ctor (System.String name, System.String value) [0x00000] in <filename unknown>:0 
  at System.Net.Http.Headers.CollectionExtensions.SetValue (System.Collections.Generic.List`1 parameters, System.String key, System.String value) [0x00000] in <filename unknown>:0 
  at System.Net.Http.Headers.ContentDispositionHeaderValue.SetValue (System.String key, System.String value) [0x00000] in <filename unknown>:0 
  at System.Net.Http.Headers.ContentDispositionHeaderValue.set_Name (System.String value) [0x00000] in <filename unknown>:0 
  at System.Net.Http.MultipartFormDataContent.AddContentDisposition (System.Net.Http.HttpContent content, System.String name, System.String fileName) [0x00000] in <filename unknown>:0 
  at System.Net.Http.MultipartFormDataContent.Add (System.Net.Http.HttpContent content, System.String name) [0x00000] in <filename unknown>:0 

.NET works perfectly with that
Comment 1 Marek Safar 2014-03-17 10:35:07 UTC
Could you attach sample of the code you are using (as this issue may be already resolved in mono 3.4)
Comment 2 Mauro 2014-09-10 09:12:00 UTC

I have recently come across this issue while using SendGrid in Android.

I have managed to reproduce the issue with the following snippet of code : 

List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>()
                new KeyValuePair<string, string>("api_user", "api_user"),
                new KeyValuePair<string, string>("api_key", "api_key"),
                new KeyValuePair<string, string>("replyto", "test user"),
                new KeyValuePair<string, string>("from", "test@home.com"),
                new KeyValuePair<string, string>("fromname", "test user"),
                new KeyValuePair<string, string>("subject", "test"),
                new KeyValuePair<string, string>("text", "test message"),
                new KeyValuePair<string, string>("html", ""),
                new KeyValuePair<string, string>("x-smtpapi", ""),
                new KeyValuePair<string, string>("to[]", "user@home.com")

            MultipartFormDataContent content = new MultipartFormDataContent();
            foreach (KeyValuePair<string, string> keyValuePair in list)
                content.Add(new StringContent(keyValuePair.Value), keyValuePair.Key);

The issue occurs on the when the "to[]" string is being created with the StringContent.

Comment 3 Marek Safar 2014-09-10 13:10:06 UTC
Fixed in master
Comment 4 Mauro 2014-09-10 13:14:47 UTC
HI Marek,

I see that the bug has been fixed in master, do you know when more or less it would be available to the public so we can use it?

Comment 5 Marek Safar 2014-09-10 13:16:18 UTC
it's available today if you download it from Monkey wrench or you wait for official Mono 3.12 release
Comment 6 Mauro 2014-09-10 13:45:08 UTC
Cool, do you know when the official release is and where is Monkey Wrench to download it?

Thanks again
Comment 7 Marek Safar 2014-09-10 13:46:35 UTC
The release should happen in about a month

Comment 8 Mauro 2014-09-11 01:11:55 UTC
Hi Marek,

Sorry to bug you again, but I'm just a litte confused as what build/file I need to download from the Monkey Wrench, could you possibly direct me in the right direction?

Thanks again
Comment 9 Marek Safar 2014-09-11 04:37:59 UTC
I just noticed we don't have latest builds for Windows, you will have to wait for official release or build it on your own
Comment 10 Mauro 2014-09-11 04:38:59 UTC
Cool, where could I download the code to do a custom build? Also, will this be in the alpha/beta channel anytime soon?
Comment 11 Marek Safar 2014-09-11 04:41:06 UTC

it should appear in alpha channel in 3-4 weeks time
Comment 12 Mauro 2014-09-11 04:53:46 UTC
Cool, I just checked the source code repository (https://github.com/mono/mono/tree/effa4c07ba850bedbe1ff54b2a5df281c058ebcb/mcs/class/System.Net.Http) and it seems that the last checkin was a while ago. Was the fix done on a separate branch?
Comment 13 Marek Safar 2014-09-11 04:55:41 UTC
You checked wrong branch, you need to browse master

Comment 14 Shruti 2014-11-27 06:44:10 UTC
I have checked this issue with creating new android application and implemented code given in comment(2).  I did not experience any exception and observed that HttpClient is supporting 'name[]' header field name format. 

This issue has been fixed.

Screencast regarding same : http://www.screencast.com/t/Nsexo0avFXPr

Environment Info :
=== Xamarin Studio ===

Version 5.7 (build 596)
Installation UUID: 67eaf3b4-f8a7-4ab4-a9df-3197350ca5dc
	Mono 3.12.0 ((detached/b75fa2b)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000046

=== Apple Developer Tools ===

Xcode 6.2 (6736)
Build 6C86e

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 880cc21
Build date: 2014-11-25 12:12:17-0500

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/ixamarin78/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		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.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 507000596
Git revision: d996e9ba6874a0d64241e43e5e6b06322ce29c84
Build date: 2014-11-25 17:17:54-05
Xamarin addins: 8ca19707b41536a391f53364ee4ff9272711feb0

=== Operating System ===

Mac OS X 10.10.0
Darwin XamnewiMac.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