我最近为我正在做的WPF应用程序创建了此代码。我正在重用代码的项目是Windows 8应用程序。代码本身是一样的,所以我真的没有看到可能是什么问题。它们之间的唯一区别当然是应用程序和正在使用的.NET Framework。在WPF应用程序中,我的目标是.NET 3.0,而对于Windows 8应用程序,我使用的是.NET 4.5。
正如您所知,这是一种扩展方法:
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。
答案 0 :(得分:2)
GetAllNetworkInterfaces
不适用于Windows应用商店(metro)应用。 MSDN Documentation表示只有GetIsNetworkAvailable
方法可供Windows应用商店应用使用。绿色公文包指示它是否可用于Windows应用商店应用。
我不知道任何可用于Windows Store应用程序的API可以为您提供所需的信息。