Bug 37430 - Unknown member Header in NSMutableUrlRequest
Summary: Unknown member Header in NSMutableUrlRequest
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 9.4 (iOS 9.2)
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2016-01-05 23:52 UTC by timothy.castle
Modified: 2016-03-09 21:40 UTC (History)
3 users (show)

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

Picture showing the error (38.22 KB, image/png)
2016-01-07 16:46 UTC, timothy.castle

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 timothy.castle 2016-01-05 23:52:45 UTC
When I try to modify the headers on a NSMutableUrlRequest, it will compile and run perfectly fine, however modifying the headers doesn't change anything. To try and figure out why, I stepped through the code and I noticed that it gives me a warning "Unknown member: Headers", however Headers is a public property of NSMutableUrlRequest, and no error is thrown when the line of code executes. I am using the following code.

NSMutableUrlRequest request =  new NSMutableUrlRequest ();
request.Headers = mydict;
request.Url = myurl;
Comment 1 Sebastien Pouliot 2016-01-07 03:12:25 UTC
This comes from


Where did you see "Unknown member: Headers" ? Logs (please attach) ? XS ? VS ? (screenshot)

IIRC not every headers can be modified programmatically. Can you provide what `mydict` contains (or better a self contained test case).
Comment 2 timothy.castle 2016-01-07 16:46:27 UTC
Created attachment 14480 [details]
Picture showing the error

Here is a picture of where the error comes up. It occurs in Xamarin Studio, and occurs with different keys for the Header. I have tried Post, User-Agent, and custom keys.
Comment 3 Sebastien Pouliot 2016-01-13 20:30:33 UTC
The picture shows a UI error from the debugger. That can be a debugger issue or, if it comes from a device build, it could be that the linker removed the `getter` (because it's unused). In any case it's unrelated to not being able to add items in the headers.

Please provide a test case that shows the issue (e.g. not being able to set "User-Agent") and we'll have a look.
Comment 4 timothy.castle 2016-01-13 22:48:36 UTC
Using this code, produces this User-Agent header.
var obj = new Object[] {"hosted"} ;
var key =  new Object[] {"User-Agent"} ;
NSDictionary dict;
dict = NSDictionary.FromObjectsAndKeys (obj, key);
request.Headers = dict;
Header: Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13C75

Also when trying to call the get function on Headers throws a null exception error, and the UI error from the debugger is present after calling "request.Headers = dict;". If this isn't the info you need please let me know and I will attempt to provide you with it.
Comment 5 Sebastien Pouliot 2016-01-15 13:50:25 UTC
Your sample is not complete (e.g. how and when did you print the header) but similar code works fine for me.

		public void A ()
			using (var obj = new NSString ("hosted"))
			using (var key = new NSString ("User-Agent"))
			using (var dict = NSMutableDictionary.FromObjectAndKey (obj, key))
			using (var request = new NSMutableUrlRequest ()) {
				request.Headers = dict;
				Console.WriteLine (request.Headers.ToString ());

This prints:

2016-01-15 08:45:05.365 monotouchtest[33928:5912629] {
    "User-Agent" = hosted;

The immediate debugging pad shows

? request.Headers
    "User-Agent" = hosted;
	Class: {ObjCRuntime.Class}
	ClassHandle (Foundation.NSMutableDictionary): 0x113588020
	ClassHandle (Foundation.NSDictionary): 0x113588020
	ClassHandle (Foundation.NSObject): 0x113588020
	Count: 1
	DebugDescription: "{\n    \"User-Agent\" = hosted;\n}"
	Description: "{\n    \"User-Agent\" = hosted;\n}"
	DescriptionInStringsFileFormat: "\"User-Agent\" = \"hosted\";\n"
	Handle: 0x7ffb9cee6890
	IsProxy: false
	Keys: {Foundation.NSObject[1]}
	ObjectEnumerator: {<__NSDictionaryObjectEnumerator: 0x7ffba0038320>}
	RetainCount: 4
	Self: {{
    "User-Agent" = hosted;
	SuperHandle: 0x12b3c4d20
	Superclass: {ObjCRuntime.Class}
	Values: {Foundation.NSObject[1]}
	Zone: {Foundation.NSZone}
	Static members: 
	Non-public members: 

It's possible that iOS change the value later (at use time) as the list of headers you cannot change (in Apple documentation) might not be complete (or up to date).

If you do not get the same results as me for the above then please:
- attach a self-contained test case that shows your issue;
- include all* version information;
- re-open the bug

* The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 6 timothy.castle 2016-01-19 20:49:14 UTC
It seems to work perfectly fine on my simulator (iPhone 6 iOS 9.2), although I can never find the header in the resulting request, however when running it on my phone (iPhone 6 iOS 9.2) I encounter the error. It only has the ClassHandle and URL members in the debugger when using device, but all members show up in the debugger when using the simulator.

using System;
using Foundation;
using UIKit;
using CoreGraphics;
namespace test
	public partial class ViewController : UIViewController
		public ViewController (IntPtr handle) : base (handle)

		public override void ViewDidLoad ()
			base.ViewDidLoad ();
			this.button.TouchUpInside += ButtonPressed; 
		public override void ViewDidLayoutSubviews()
		private void ButtonPressed (object sender, EventArgs e)
			var webView = new UIWebView (new CGRect (0, 30, this.View.Frame.Width, (this.View.Frame.Height - 30)));
			this.View.AddSubview (webView);
			NSMutableUrlRequest request = new NSMutableUrlRequest ();
			var obj = new NSString ("hosted");
			var key = new NSString ("User-Agent");
			NSDictionary dict;
			request.Url = new NSUrl ("http://example.com");
			dict = NSMutableDictionary.FromObjectAndKey (obj, key);
			request.Headers = dict;
			webView.LoadRequest ((request));
			Console.WriteLine (request.Headers.ToString ());
			webView.ScalesPageToFit = true;

		public override void DidReceiveMemoryWarning ()
			base.DidReceiveMemoryWarning ();
			// Release any cached data, images, etc that aren't in use.

=== Xamarin Studio ===

Version 5.10.1 (build 6)
Installation UUID: 400add93-acc3-422b-9b38-25338cf9f299
	Mono 4.2.1 (explicit/6dd2d0d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010102

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.2 (9548)
Build 7C68

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 7322991
Branch: master
Build date: 2015-12-08 16:20:29-0500

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/castle/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)

SDK Tools Version: 24.4.0
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.1
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Starter Edition)

=== Build Information ===

Release ID: 510010006
Git revision: 0b60eecdb531933734519c13257d16a780274aab
Build date: 2015-12-04 20:28:20-05
Xamarin addins: 9876fd7c9837977178411ec7375b4352c0a0d6af
Build lane: monodevelop-lion-cycle6-baseline

=== Operating System ===

Mac OS X 10.11.2
Darwin Timothys-MacBook-Pro.local 15.2.0 Darwin Kernel Version 15.2.0
    Fri Nov 13 19:56:56 PST 2015
    root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64
Comment 7 Sebastien Pouliot 2016-03-09 21:40:55 UTC
Like explained in comment #3 this is not a bug. What you see in the debugger is only what's included in your .app and, by default, the linker is:

- disabled on simulator builds, so you'll see all properties on any type;

- enabled on device builds, so you'll only see properties that are used by your applications (source) or internally by the SDK.