Bug 42738 - Socket.LocalEndpoint throws after BeginConnect (Ipv6)
Summary: Socket.LocalEndpoint throws after BeginConnect (Ipv6)
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Future Release
Assignee: marcos.henrich
URL:
Depends on:
Blocks:
 
Reported: 2016-07-22 11:11 UTC by Karl Nilsson
Modified: 2017-05-06 22:18 UTC (History)
6 users (show)

Tags:
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 GitHub or Developer Community 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 FIXED

Description Karl Nilsson 2016-07-22 11:11:04 UTC
Best explained with a small repro:

open System.Net
open System.Net.Sockets
//create new socket with Ipv6 address family
let s = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp)
//do async connect against localhost
Async.FromBeginEnd((fun (ac, o) -> s.BeginConnect("localhost", 5234, ac, o)), s.EndConnect)
|> Async.RunSynchronously
s.LocalEndPoint //accessing this throws


Exception:

System.ArgumentException: The IPEndPoint was created using InterNetwork AddressFamily but SocketAddress contains InterNetworkV6 instead, please use the same type.
  at System.Net.IPEndPoint.Create (System.Net.SocketAddress socketAddress) <0x7d509f8 + 0x0051b> in <filename unknown>:0
  at System.Net.Sockets.Socket.get_LocalEndPoint () <0x7d50828 + 0x0005f> in <filename unknown>:0
  at <StartupCode$FSI_0004>.$FSI_0004.main@ () <0x7d507a0 + 0x00017> in <filename unknown>:0
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x267c270 + 0x000a1> in <filename unknown>:0
Stopped due to error


If you use the sync 'Connect' instead this does not happen.
Comment 1 Rodrigo Kumpera 2016-07-23 00:29:30 UTC
I reproduce it with master.

It repros if you setup a socket listening on everything.
Comment 2 Rodrigo Kumpera 2016-07-23 00:30:36 UTC
This is the snippet I used to setup the listening side:

var x = new TcpListener (IPAddress.Any, 5234);
x.Start ();
var s = x.AcceptSocket();
Comment 3 Kerry Jiang 2016-08-06 14:10:23 UTC
I met this problem too.
https://github.com/kerryjiang/SuperSocket.ClientEngine/issues/38

The problem might be the remote endpoint is a IPV6 one but the local bind endpoint is IPv4 one.
Comment 4 Mikayla Hutchinson [MSFT] 2017-04-18 01:05:31 UTC
https://github.com/mono/mono/pull/4702
Comment 5 Mikayla Hutchinson [MSFT] 2017-05-06 22:18:26 UTC
This has been fixed.