【发布时间】:2013-03-25 16:22:40
【问题描述】:
我最近为我正在做的 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())
它会导致错误提示 GetAllNetworkInterfaces() 在 NetworkInterface 中不存在。这是确切的错误:
Error 15 'System.Net.NetworkInformation.NetworkInterface' does not contain a definition for 'GetAllNetworkInterfaces'
关于在 Windows 8 应用程序中重用 WPF 应用程序的代码,有什么我不知道的吗?
更新:使用 ianainterfacetype 我能够修复一半的扩展方法,因为我能够分辨它们是以太网、无线还是隧道。我仍在寻找一种方法来判断它们是由 VirtualBox 还是由 VMware 创建的。
想要了解ianainterfacetype 的人可以查找信息here。
【问题讨论】:
-
这可能会帮助您开始使用 WinRT 的网络 API:stackoverflow.com/questions/10336521/query-local-ip-address/…
标签: c# wpf windows-8 code-reuse network-interface