Bug 15128 - System.Net.Http
Summary: System.Net.Http
Status: RESOLVED DUPLICATE of bug 8719
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: 7.0.0.x
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-10-02 11:31 UTC by gauzza
Modified: 2014-06-02 04:44 UTC (History)
5 users (show)

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


Attachments
Sample project (1.42 MB, application/zip)
2013-10-02 11:31 UTC, gauzza
Details


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 DUPLICATE of bug 8719

Description gauzza 2013-10-02 11:31:42 UTC
Created attachment 5039 [details]
Sample project

Running the following code throws an invalid format exception.  If I copy the userAgent into a VS 2012 .net 4.0 project it is able to parse the userAgent fine.
	
using (var webView = new UIWebView()) {
				var userAgent = webView.EvaluateJavascript ("navigator.userAgent");
				var client = new HttpClient();
				client.DefaultRequestHeaders.UserAgent.ParseAdd(userAgent);
			}
Comment 1 Rolf Bjarne Kvinge [MSFT] 2013-10-02 17:06:19 UTC
The test case runs fine for me on both the iOS simulator and an iPad3.

Can you add the full exception information, with a complete stack trace and message?
Comment 2 gauzza 2013-10-02 21:24:40 UTC
Instance	{System.FormatException: Invalid format.   at System.Net.Http.Headers.HttpHeaders.AddInternal (System.String name, IEnumerable`1 values, System.Net.Http.Headers.HeaderInfo headerInfo, Boolean ignoreInvalid) [0x0004c] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:195    at System.Net.Http.Headers.HttpHeaders.AddValue (System.String value, System.Net.Http.Headers.HeaderInfo headerInfo, Boolean ignoreInvalid) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:175    at System.Net.Http.Headers.HttpHeaderValueCollection`1[System.Net.Http.Headers.ProductInfoHeaderValue].ParseAdd (System.String input) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaderValueCollection.cs:86    at testingZone.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00062] in /Users/matt/Projects/testingZone/testingZone/AppDelegate.cs:37    at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)   at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38    at testingZone.Application.Main (System.String[] args) [0x00008] in /Users/matt/Projects/testingZone/testingZone/Main.cs:16 }	System.FormatException
Comment 3 gauzza 2013-10-02 21:30:09 UTC
Unhandled Exception:
System.FormatException: Invalid format.
  at System.Net.Http.Headers.HttpHeaders.AddInternal (System.String name, IEnumerable`1 values, System.Net.Http.Headers.HeaderInfo headerInfo, Boolean ignoreInvalid) [0x0004c] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:195 
  at System.Net.Http.Headers.HttpHeaders.AddValue (System.String value, System.Net.Http.Headers.HeaderInfo headerInfo, Boolean ignoreInvalid) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:175 
  at System.Net.Http.Headers.HttpHeaderValueCollection`1[System.Net.Http.Headers.ProductInfoHeaderValue].ParseAdd (System.String input) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaderValueCollection.cs:86 
  at testingZone.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00062] in /Users/matt/Projects/testingZone/testingZone/AppDelegate.cs:37 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
  at testingZone.Application.Main (System.String[] args) [0x00008] in /Users/matt/Projects/testingZone/testingZone/Main.cs:16 
2013-10-02 21:23:57.759 testingZone[1855:a0b] Unhandled managed exception: Invalid format. (System.FormatException)
  at System.Net.Http.Headers.HttpHeaders.AddInternal (System.String name, IEnumerable`1 values, System.Net.Http.Headers.HeaderInfo headerInfo, Boolean ignoreInvalid) [0x0004c] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:195 
  at System.Net.Http.Headers.HttpHeaders.AddValue (System.String value, System.Net.Http.Headers.HeaderInfo headerInfo, Boolean ignoreInvalid) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaders.cs:175 
  at System.Net.Http.Headers.HttpHeaderValueCollection`1[System.Net.Http.Headers.ProductInfoHeaderValue].ParseAdd (System.String input) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Net.Http/System.Net.Http.Headers/HttpHeaderValueCollection.cs:86 
  at testingZone.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00062] in /Users/matt/Projects/testingZone/testingZone/AppDelegate.cs:37 
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
  at testingZone.Application.Main (System.String[] args) [0x00008] in /Users/matt/Projects/testingZone/testingZone/Main.cs:16
Comment 4 Rolf Bjarne Kvinge [MSFT] 2013-10-03 05:08:01 UTC
Can you print out the value of userAgent just before calling ParseAdd?

Here are mine:
simulator: Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10A403
device: Mozilla/5.0 (iPad; CPU OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329

It looks like yours must be different somehow.
Comment 5 Marek Safar 2013-10-03 08:50:54 UTC
What version are you using ? Something very similar was fixed few weeks ago.
Comment 6 gauzza 2013-10-03 09:17:24 UTC
UserAgent:
Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11A465
Comment 7 gauzza 2013-10-03 09:17:57 UTC
4.0.12 (build 3)
Comment 8 gauzza 2013-10-03 09:19:04 UTC
=== Xamarin Studio ===

Version 4.0.12 (build 3)
Installation UUID: 835b0b3e-2174-458c-88c0-251acfd68a02
Runtime:
	Mono 3.2.3 ((no/8d3b4b7)
	GTK 2.24.20
	GTK# (2.12.0.0)
	Package version: 302030000

=== Apple Developer Tools ===

Xcode 5.0 (3332.25)
Build 5A1413

=== Xamarin.iOS ===

Version: 7.0.1.4 (Business Edition)
Hash: 4cfca2f
Branch: 
Build date: 2013-20-09 23:14:32-0400

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.Android ===

Version: 4.8.1 (Starter Edition)
Android SDK: /Users/matt/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
Java SDK: /usr
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)

=== Build Information ===

Release ID: 400120003
Git revision: 593d7acb1cb78ceeeb482d5133cf1fe514467e39
Build date: 2013-08-07 20:30:53+0000
Xamarin addins: 25a0858b281923e666b09259ad4746b774e0a873

=== Operating System ===

Mac OS X 10.8.5
Darwin matt-mac 12.5.0 Darwin Kernel Version 12.5.0
    Mon Jul 29 16:33:49 PDT 2013
    root:xnu-2050.48.11~1/RELEASE_X86_64 x86_64
Comment 9 Marek Safar 2013-10-03 12:16:01 UTC
The fix has not been released yet (it's in master only). It should be included in 7.0.3

*** This bug has been marked as a duplicate of bug 8719 ***
Comment 10 Pete Miller 2014-05-31 19:09:37 UTC
Just installed latest version of all Xamarin tools and this bug is still present, causing most System.Net.Http implementations which use the User-Agent header to fail. Even the following simple console app fails under OS X using NuGet release of System.Net.Http (v 2.2.22):

ProductInfoHeaderValue testEntry;
var sucess = ProductInfoHeaderValue.TryParse (
	"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)",
	out testEntry);
Console.WriteLine (sucess ? "success" : "fail");

[FAIL]
Comment 11 Marek Safar 2014-06-02 04:39:14 UTC
NuGet release of System.Net.Http (v 2.2.22) is not Mono code therefore this is wrong place to report issues against it.

Secondly your attached code fail exactly same on .net as it does on mono.
Comment 12 Pete Miller 2014-06-02 04:44:23 UTC
OK thanks, will confirm, and then report in other places. Seemed on-topic as is same issue as reported above.