我将System.Net.Ping
NuGet 包添加到空白的 UWP 项目中,并在 Mainpage.xaml.cs
中引用了 System.Net.NetworkInformation
命名空间。
在主页构造函数中,我刚刚写了Ping ping = new Ping()
.
编译这个简单的示例会在启动时引发以下异常:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Ping, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Net.Ping, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at App2.MainPage..ctor()
at App2.App2_XamlTypeInfo.XamlTypeInfoProvider.Activate_0_MainPage()
at App2.App2_XamlTypeInfo.XamlUserType.ActivateInstance()
at Windows.UI.Xaml.Controls.Frame.Navigate(Type sourcePageType, Object parameter)
at App2.App.OnLaunched(LaunchActivatedEventArgs e)} System.IO.FileNotFoundException
NuGet 包System.Net.Ping
当前在版本 4.3.0 和 4.0.0 中可用,但两者的行为相同。
截至本答案之日,UWP 平台尚不支持类System.Net.NetworkInformation.Ping
。有关详细信息,请查看此链接。
尝试添加对 System.Net.Utilities 而不是 System.Net.Ping 的引用