2016-08-30 102 views
0

我認爲這可能與依賴關係有關,但我不太確定。.net核心中缺少方法例外

所以我想請檢查TCP連接使用擴展方法我發現here仍然活躍,但我發現了一個缺失的方法例外:

「未找到方法:「系統。 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-*" 
} 

我在正確的軌道上?我將如何解決它?

+0

您是否仔細檢查過您的版本是否與支持該代碼的版本相同? – Missy

+0

我知道它不是相同的版本,但[文檔](https://msdn.microsoft.com/en-us/library/system.net.networkinformation.tcpconnectioninformation.localendpoint(v = vs.110).aspx)似乎是一致的。 – hereswilson

+1

4.0.10-beta-23123,呃,那些版本號讓任何人的眼睛流血。看起來你只是一直在挖掘一個參考彙編,直到編譯器開心。運行時間不快樂並不是一個很大的謎團。該文檔不會對此有任何疑問,只能在完整的.NET Framework版本的.NET Framework上使用。 –

回答

1

嘗試添加system.net.security程序包,因爲system.net.networkinformation取決於安全程序包。它可能沒有自動加載依賴關係。