我最近为我正在做的WPF应用程序创建了此代码。我重用代码的项目是Windows 8应用程序。代码本身是相同的,所以我真的不知道可能是什么问题。它们之间的唯一区别当然是应用程序和正在使用的.NET Framework。在WPF应用程序中,我的目标是.NET 3.0以及我使用.NET 4.5的Windows 8应用程序。网络接口不包含“”的定义
可以这样说,这是一个扩展方法:
public static bool isTunnel(this NetworkInterface adapter)
{
return adapter.NetworkInterfaceType == NetworkInterfaceType.Tunnel;
}
它给出了该方法的错误是:
Error 3 'System.Net.NetworkInformation.NetworkInterface' does not contain a definition for 'NetworkInterfaceType' and no extension method 'NetworkInterfaceType' accepting a first argument of type 'System.Net.NetworkInformation.NetworkInterface' could be found (are you missing a using directive or an assembly reference?)
Error 4 The name 'NetworkInterfaceType' does not exist in the current context
在我的模型类我有一个类似的问题。在此行上:
foreach (NetworkInterface adapter in NetworkInterface.GetAllNetworkInterfaces())
它会导致错误,指出在NetworkInterface中不存在GetAllNetworkInterfaces()。这是确切的错误:
Error 15 'System.Net.NetworkInformation.NetworkInterface' does not contain a definition for 'GetAllNetworkInterfaces'
是否有什么,我不知道在Windows 8应用程序中重用WPF应用程序的代码?
更新:使用ianainterfacetype我能解决一半的我的扩展方法,因为我能够告诉我们,如果他们是以太网,无线,或隧道。我仍在寻找一种方法来确定它们是否由VirtualBox或VMware创建。
对于那些想了解ianainterfacetype的人,你可以找到信息here。
这可能会帮助您开始使用WinRT的网络API:http://stackoverflow.com/questions/10336521/query-local-ip-address/10456778#10456778 – Phil 2013-03-25 17:09:33