Bug 44406

Summary: Xamarin.Mac.Socket exception:An address incompatible with the requested protocol was used
Product: [Mono] Class Libraries Reporter: Denis Davydov <ddavydov>
Component: SystemAssignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: ddavydov, kvloover, masafa, mono-bugs+monomac, mono-bugs+mono, mono-bugs+runtime
Priority: ---    
Version: 4.6.0 (C8)   
Target Milestone: Untriaged   
Hardware: PC   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Project for reproduce

Description Denis Davydov 2016-09-16 07:58:00 UTC
Created attachment 17530 [details]
Project for reproduce

Hi.
We use PusherClient  (https://www.nuget.org/packages/PusherClient/) in our project.
It has worked perfectly(on previous version) until I updated Xamarin.Mac and Mono to latest version. I use stable channel.

Now I see this error:

2016-09-16 10:34:50.665 TestPusherClient[1504:52164] 
Unhandled Exception:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Sockets.SocketException: An address incompatible with the requested protocol was used
  at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x00057] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.10.0.99/src/mono/mcs/class/System/System.Net.Sockets/Socket.cs:209 
  at System.Net.Sockets.Socket.ConnectAsync (System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType, System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.10.0.99/src/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1361 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.10.0.99/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:305 
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
  at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/3508/c1e5fa01/source/xamarin-macios/src/AppKit/NSApplication.cs:94 
  at TestPusherClient.MainClass.Main (System.String[] args) [0x00007] in /Users/alex/Projects/TestPusherClient/TestPusherClient/Main.cs:10 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.Sockets.SocketException: An address incompatible with the requested protocol was used
  at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x00057] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.10.0.99/src/mono/mcs/class/System/System.Net.Sockets/Socket.cs:209 
  at System.Net.Sockets.Socket.ConnectAsync (System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType, System.Net.Sockets.SocketAsyncEventArgs e) [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.10.0.99/src/mono/mcs/class/System/System.Net.Sockets/Socket.cs:1361 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /Library/Frameworks/Xamarin.Mac.framework/Versions/2.10.0.99/src/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:305 
   --- End of inner exception stack trace ---
  at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
  at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/3508/c1e5fa01/source/xamarin-macios/src/AppKit/NSApplication.cs:94 
  at TestPusherClient.MainClass.Main (System.String[] args) [0x00007] in /Users/alex/Projects/TestPusherClient/TestPusherClient/Main.cs:10 


My details:
Xamarin Studio Community
Version 6.1 (build 5441)
Installation UUID: a2ad89a8-387d-4bac-b970-7f49bc55a3be
Runtime:
	Mono 4.6.0 (mono-4.6.0-branch/746756c) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406000245

NuGet
Version: 3.4.3.0

Xamarin.Profiler
Not Installed

Xamarin.Android
Not Installed

Xamarin Android Player
Not Installed

Apple Developer Tools
Xcode 7.3.1 (10188.1)
Build 7D1014

Xamarin.iOS
Not Installed

Xamarin.Mac
Version: 2.10.0.99 (Xamarin Studio Community)

Build Information
Release ID: 601005441
Git revision: 68292d1ab289911c815ddc715dd7cc29a9752f9f
Build date: 2016-09-09 04:43:23-04
Xamarin addins: ed25d008672663eeb9db55f1ccecb3c24d2fd3b2
Build lane: monodevelop-lion-cycle8

Operating System
Mac OS X 10.11.6
Darwin DDavydovs-Mac.local 15.6.0 Darwin Kernel Version 15.6.0
    Mon Aug 29 20:21:34 PDT 2016
    root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64

In attachements test project.

This functionality critical for our project. And this error stops us.
Thanks in advance.
Comment 1 Denis Davydov 2016-09-16 11:36:38 UTC
Additional info after digging in code 

using (var s = new System.Net.Sockets.Socket
							(System.Net.Sockets.AddressFamily.Unspecified,
							   System.Net.Sockets.SocketType.Stream,
							   System.Net.Sockets.ProtocolType.Tcp))
{
}

This code does not work and fail with the same exception.
An address incompatible with the requested protocol was used

Address looks like 
wss://ws.pusherapp.com/app/7899dd5cb232af88083d?protocol=5&client=pusher-dotnet-client&version=0.0.1"
Comment 2 Chris Hamons 2016-09-16 15:38:43 UTC
I can reproduce this without Xamarin.Mac at all:

https://gist.github.com/chamons/42dcf78a788e0ebacab1a1d741f29c7d

If this worked before, it appears to be a mono issue. 

Bumping to the right group.
Comment 3 Marek Safar 2016-09-20 16:10:55 UTC
This comes from Socket_internal icall
Comment 4 Kevin Van Looveren 2016-09-26 11:13:27 UTC
I was having the same issue trying to connect to Discord using the Discord.net nuget.

Downgrading to Mono 4.4 resolved the issue for me. So it would appear to be a bug in 4.6. See if this helps for you.
Comment 5 Denis Davydov 2016-10-17 08:56:50 UTC
Hi. 
Any update on this?
Comment 6 Marek Safar 2016-10-18 15:53:49 UTC
Fixed in master and Mono 4.8

Note for myself: Mono 4.6 introduced new ConnectAsync overload which the library is calling via reflection and it was not handling DnsEndPoint at all.