Bug 36459 - System.Net.Sockets.Socket throws System.Net.Sockets.SocketException: Access denied
Summary: System.Net.Sockets.Socket throws System.Net.Sockets.SocketException: Access d...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-12-02 06:09 UTC by Prashant Cholachagudda
Modified: 2015-12-03 07:40 UTC (History)
2 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 Prashant Cholachagudda 2015-12-02 06:09:48 UTC
# Steps to reproduce
Customer's code is as below: (_socket is System.Net.Sockets.Socket)

_socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
_socket.ReceiveTimeout = ReadTimeout;
_socket.SendTimeout = ReadTimeout;
_socket.Blocking = true;
_socket.Connect(_connectedDevice.IpAddress, _connectedDevice.Port); //throws Access Denied

# Expected behavior
The socket connection should be connected 

# Actual behavior
Throws `Access denied` exception

# Supplemental info (logs, images, videos)
Stack trace - 
2015-12-01 09:02:54.922 GarudaiOS[5756:2050614] Error - Open: System.Net.Sockets.SocketException: Access denied
at System.Net.Sockets.Socket.Connect (System.Net.IPAddress[] addresses, Int32 port) [0x0010a] in /Users/builder/data/lanes/2356/3c0ec355/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1203
at System.Net.Sockets.Socket.Connect (System.String host, Int32 port) [0x00000] in /Users/builder/data/lanes/2356/3c0ec355/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1161
at Garuda.iOS.Services.IosWifiConnection2.Connect () [0x00098] in /Users/p202admin/projekt202/coherent-labmaxpro-mobile.git/Garuda/src/Garuda.iOS/Services/IosWifiConnection2.cs:195
at Garuda.iOS.Services.IosWifiConnection2.Open (System.String portName) [0x00028] in /Users/p202admin/projekt202/coherent-labmaxpro-mobile.git/Garuda/src/Garuda.iOS/Services/IosWifiConnection2.cs:93
at PhoenixLibrary.Communicator.Open (System.String portName) [0x0002b] in /Users/p202admin/projekt202/coherent-labmaxpro-mobile.git/Garuda/src/Garuda.Core/Phoenix/PhoenixLibrary/Communicator.cs:82
at PhoenixLibrary.Device.Open (System.String portName) [0x00023] in /Users/p202admin/projekt202/coherent-labmaxpro-mobile.git/Garuda/src/Garuda.Core/Phoenix/PhoenixLibrary/Device.cs:80
at PhoenixLibrary.Meter.Open (System.String portName) [0x00045] in /Users/p202admin/projekt202/coherent-labmaxpro-mobile.git/Garuda/src/Garuda.Core/Phoenix/PhoenixLibrary/Meter.cs:163

# Test environment (full version information)

=== Xamarin Studio ===

Version 5.10 (build 871)

Installation UUID: 9fba1738-8773-4563-bf9e-5ccce8cc534d


Mono 4.2.1 (explicit/6dd2d0d)

GTK+ 2.24.23 (Raleigh theme)

Package version: 402010102

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.1.1 (9081)

Build 7B1005

=== Xamarin.iOS ===

Version: (Enterprise Edition)

Hash: 3c0ec35

Branch: master

Build date: 2015-11-12 13:05:39-0500

=== Xamarin.Android ===

Version: (Enterprise Edition)

Android SDK: /Users/p202admin/Library/Developer/Xamarin/android-sdk-macosx

Supported Android versions:

2.3 (API level 10)

4.0.3 (API level 15)

4.4 (API level 19)

5.0 (API level 21)

SDK Tools Version: 24.3.2

SDK Platform Tools Version: 22.0.0

SDK Build Tools Version: 23.0.0

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 Android Player ===

Not Installed

=== Xamarin.Mac ===

Version: (Starter 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

Darwin KernelCorn 14.5.0 Darwin Kernel Version 14.5.0

Wed Jul 29 02:26:53 PDT 2015

root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 1 Sebastien Pouliot 2015-12-02 06:45:03 UTC
That's unlikely to be a general issue with Sockets as our whole HTTP stack is built on top of it.

@Prashant it's not clear, did you personally confirm the issue ? 

In any case please attach your (or the customer) test case. The code above is incomplete and uses variables for which we do not know the values.
Comment 2 Prashant Cholachagudda 2015-12-03 07:40:55 UTC
Sorry, it was false alarm.

I guess, these two reasons caused the exception
1. The port was already being used.
2. iOS uses both IPv6 and IPv4, we have to mention address family during the initialisation

ex: var s = new Socket(myip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);