Bug 21889 - BasicHttpBinding AllowCookies does not create HttpCookieContainerBindingElement when set to true
Summary: BasicHttpBinding AllowCookies does not create HttpCookieContainerBindingEleme...
Status: RESOLVED DUPLICATE of bug 11307
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.12.4
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2014-08-06 17:33 UTC by John Miller [MSFT]
Modified: 2014-08-29 14:05 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 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 John Miller [MSFT] 2014-08-06 17:33:04 UTC

   AllowCookies seems to have no effect. 

    > var binding = new BasicHttpBinding();
    > binding.Security.Mode = BasicHttpSecurityMode.Transport;
    > binding.AllowCookies = true; 
    > bool l = await ws.Login(binding, "username", "password");

**Steps to Reproduce:**

   1. Run the attached sample.
   2. Press the Login button.

**Actual Results:**

   An exception occurs:

> Unable to set the CookieContainer. Please make sure the binding contains an HttpCookieContainerBindingElement.

>  at Test.PCL.ServiceReference1.AuthenticationServiceClient.set_CookieContainer (System.Net.CookieContainer value) [0x00027] in /Users/John/Downloads/PCLWebServiceTest/Test.PCL/Service >References/ServiceReference1/Reference.cs:177 
>  at Test.PCL.WebServices.Login (System.ServiceModel.Channels.Binding binding, System.String userName, System.String password) [0x00044] in /Users/John/Downloads/PCLWebServiceTest/Test.PCL/WebServices.cs:26 
>--- End of stack trace from previous location where exception was thrown ---
>  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <filename unknown>:0 
>  at System.Runtime.CompilerServices.TaskAwaiter`1[System.Boolean].GetResult () [0x00000] in <filename unknown>:0 
>  at Test.Droid.Activity1+<button_Click>c__async0.MoveNext () [0x000be] in /Users/John/Downloads/PCLWebServiceTest/Test.Droid/Activity1.cs:52 

**Expected Results:**

   await ws.Login(...) returns true and successful login.

**Build Date & Platform:**

   Tested with:
   XA 4.12.6
   XA 4.14
   Mono 3.6

**Additional Information:**
   This seems to be a workaround, but HttpCookieContainerBindingElement is obsolete.

> var _binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
> var customBinding = new CustomBinding(_binding);
> customBinding.Elements.Insert(0, new HttpCookieContainerBindingElement()); // Obsolete warning
> Binding binding = customBinding;

   There is also a WinForms example in the test case. The code in the WinForms project also fails (On Mac with Mono) with the same error, and the workaround does not seem to work. The same WinForms project works fine on Windows with the AllowCookie setting.
Comment 2 Udham Singh 2014-08-07 14:28:37 UTC
I have checked this issue with 'Test Case' attached in comment 1 and able to reproduce this. To reproduce this issue I have followed the steps mentioned in bug description.

Screencast : http://screencast.com/t/QTX8ZoL0
Adb Logcat : https://gist.github.com/anonymous/139d99070b4b47c333d2

Note : I have checked this issue with device Samsung Galaxy Note 3( android version 4.4.2)

Environment Info : 

=== Xamarin Studio ===

Version 5.2 (build 386)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
	Mono 3.6.0 ((no/f540f8a)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 306000039

=== Xamarin.Android ===

Version: 4.14.0 (Enterprise Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		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)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: 606f31a
Build date: 2014-08-01 15:27:48-0400

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Build Information ===

Release ID: 502000386
Git revision: e6a54dee5376e6e7a2d9982695b060fddc09e65d
Build date: 2014-08-04 14:03:28-04
Xamarin addins: 2b5a5c26ac2ee74c6e91a8d24ef44d0ca9cb74d0

=== Operating System ===

Mac OS X 10.9.2
Darwin MacMini.local 13.1.0 Darwin Kernel Version 13.1.0
    Thu Jan 16 19:40:37 PST 2014
    root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2014-08-29 12:41:16 UTC
I suspect this is a duplicate of bug 11307.

I was able to reproduce the "Unable to set the CookieContainer" error on the current stable versions.

I then ran the test project on the current beta versions (that include the fix for bug 11307). I tested on an Android device and an Android emulator. In both cases the login completed without throwing the "Unable to set the CookieContainer" exception.

Instead, the alert dialog shows:
"Logged in True"

## Version information (beta channel)

Xamarin.Android 4.16.0
Xamarin 3.5.55

*** This bug has been marked as a duplicate of bug 11307 ***
Comment 4 Yuri 2014-08-29 13:52:48 UTC
This bug was created because #11307 is marked as resolved. It is not resolved.
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2014-08-29 14:05:10 UTC
@Yuri, the test case attached to this bug and the test case attached to bug 11307 both run correctly for me on the current beta versions.

Unfortunately the "Resolved" status only indicates that a fix for a bug has been applied to the source code. Currently Xamarin's Bugzilla does not have a separate status to indicate that a fix for a bug has been released to the stable channel.

If you are able to reproduce the "Unable to set the CookieContainer" exception after upgrading to the beta channel using the test case attached to this bug report, be sure to let me know.

If, after upgrading to the beta channel, you are not able to reproduce the exception using the test case attached to this bug report, but you _are_ able to reproduce it with another app, the best next step would be to clean and zip up a sample project that demonstrates the problem, and then send it in to contact@xamarin.com, or attach it to a new bug report that includes the detailed steps to reproduce, actual results, expected results, and complete version information. (See also: https://bugzilla.xamarin.com/page.cgi?id=bug-writing.html)

Thanks in advance!