Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 网络接口不包含“的定义”&引用;_C#_Wpf_Windows 8_Code Reuse_Network Interface - Fatal编程技术网

C# 网络接口不包含“的定义”&引用;

C# 网络接口不包含“的定义”&引用;,c#,wpf,windows-8,code-reuse,network-interface,C#,Wpf,Windows 8,Code Reuse,Network Interface,我最近为我正在做的WPF应用程序创建了这段代码。我重用代码的项目是一个Windows8应用程序。代码本身是相同的,所以我真的看不出有什么问题。当然,它们之间的唯一区别是应用程序和所使用的.NET Framework。在WPF应用程序中,我的目标是.NET3.0,而在Windows8应用程序中,我使用的是.NET4.5 可以看出,这是一种扩展方法: public static bool isTunnel(this NetworkInterface adapter) {

我最近为我正在做的WPF应用程序创建了这段代码。我重用代码的项目是一个Windows8应用程序。代码本身是相同的,所以我真的看不出有什么问题。当然,它们之间的唯一区别是应用程序和所使用的.NET Framework。在WPF应用程序中,我的目标是.NET3.0,而在Windows8应用程序中,我使用的是.NET4.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'
关于在Windows8应用程序中重用WPF应用程序中的代码,有什么我不知道的吗

更新:使用ianainterfacetype,我能够修复一半的扩展方法,因为我能够分辨它们是以太网、无线还是隧道。我仍在寻找一种方法来判断它们是由VirtualBox还是VMware创建的


对于那些想了解iAnainterface类型的人,您可以找到相关信息。

GetAllNetworkInterfaces
不适用于Windows应用商店(metro)应用程序。表示只有
GetIsNetworkAvailable
方法可用于Windows应用商店应用。绿色公文包表示它是否可用于Windows应用商店应用程序


我不知道Windows应用商店应用程序中有任何API可以提供您正在查找的信息。

@RandomlyKnighted不幸的是,我认为没有。我不记得了。那是5年前的事了。我将查找我的旧代码,如果我找到它,然后我将报告。这可能会帮助您开始使用WinRT的网络API: