.net核心中缺少方法异常

时间:2016-08-30 14:48:03

标签: c# exception .net-core

我认为这可能与依赖关系有关,但我并不确定。

因此,我尝试使用我找到here的扩展方法检查TCP连接是否仍处于活动状态,但是我遇到了丢失的方法异常:

"找不到方法:' System.Net.IPEndPoint System.Net.NetworkInformation.TcpConnectionInformation.get_LocalEndPoint()'"

自方法seems to exist以来,我有点困惑。

以下是代码:

 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;

        }

和JSON文件,我认为在引用NetworkInformation方面可能存在问题:

{
  "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-*"
}

我是否在正确的轨道上?我该如何解决?

1 个答案:

答案 0 :(得分:1)

尝试添加system.net.security包,因为system.net.networkinformation取决于安全包。它可能没有自动加载依赖项。