0

I think this may have something to do with the dependencies, but I'm not really sure.

So I'm trying to check to see if a TCP connection is still active using the extension method I found here, but I'm getting a missing method exception:

"Method not found: 'System.Net.IPEndPoint System.Net.NetworkInformation.TcpConnectionInformation.get_LocalEndPoint()'"

Which I'm a little confused on since the method seems to exist.

Here's the code:

 public static TcpState GetState(this TcpClient tcpClient)
        {

                var status = IPGlobalProperties.GetIPGlobalProperties()
                                               .GetActiveTcpConnections()
                                               .SingleOrDefault(x => x.LocalEndPoint.Equals(tcpClient.Client.LocalEndPoint));

                return status != null ? status.State : TcpState.Unknown;

        }

and the JSON file where I think there might be a problem in how NetworkInformation is referenced:

{
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.0"
        }
      },
      "imports": "dnxcore50"
    }
  },
  "dependencies": {
    "system.net.networkinformation": "4.0.10-beta-23123"

  },
  "version": "1.0.0-*"
}

Am I on the right track? How would I fix it?

Community
  • 1
  • 1
hereswilson
  • 185
  • 1
  • 4
  • 15
  • Did you double check that your version is the same as the one that supports that code? – Missy Aug 30 '16 at 14:53
  • I know it's not the same version, but the [documentation](https://msdn.microsoft.com/en-us/library/system.net.networkinformation.tcpconnectioninformation.localendpoint(v=vs.110).aspx) seems to be consistent. – hereswilson Aug 30 '16 at 14:59
  • 1
    4.0.10-beta-23123, ugh, those version numbers make anybody's eyes bleed. Looks like you just kept digging for a reference assembly until the compiler was happy. That the runtime isn't happy is not a great mystery. The documentation makes no bones about it either, only available on the full desktop version of the .NET Framework. – Hans Passant Aug 30 '16 at 15:10
  • @HansPassant ok so I was on the right track. I was getting an error that TcpState could not be found and adding that dependency seemed to fix it. So I need to get the full version? what version am I using? – hereswilson Aug 30 '16 at 15:32
  • 1
    try adding `system.net.security` package also, as `networkinformation` depends on `security` package. It might not be loaded dependencies automatically. – Venkata Dorisala Aug 30 '16 at 16:07
  • @Venky where exactly? in the dependencies? – hereswilson Aug 30 '16 at 16:40
  • @Venky yeah I guess that fixed it. I also got rid of the beta version. – hereswilson Aug 31 '16 at 13:01

1 Answers1

1

Try adding system.net.security package also, as system.net.networkinformation depends on security package. It might not have loaded dependencies automatically.

Venkata Dorisala
  • 4,783
  • 7
  • 49
  • 90