我正在创建一个小程序来 ping 网络中的一台计算机。 为此,我尝试使用类 ping,来自
namespace System.Net.NetworkInformation.Ping
我正在使用 ASP.NET 5.0,所以我有一个 project.json 文件和我的依赖项
{
"version": "1.0.0-*",
"dependencies": {
"NetworkSniffer": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0.0-beta2"
},
"commands": {
"run": "run"
},
"frameworks": {
"aspnet50": {
"dependencies": {
"System.Console": "4.0.0-beta-22231",
"System.Net.NetworkInformation": "4.0.10-beta-22231"
}
},
"aspnetcore50": {
"dependencies": {
"System.Console": "4.0.0-beta-22231",
"System.Net.NetworkInformation": "4.0.10-beta-22231"
}
}
}
}
仍然给出错误的控制台代码的简化版本是:
using System.Net.NetworkInformation;
namespace TestApp
{
public class Program
{
public static void Main(string[] args)
{
Ping p = new Ping();
}
}
}
尝试编译此代码时的完整错误是:
Code:Error CS0246 Description:The type or namespace name 'Ping' could not be found (are you missing a using directive or an assembly reference?) Project:TestApp.ASP.NET Core 5.0 file:Program.cs line:9
最佳答案
问题是 Ping 不在 CoreCLR (aspnetcore50
) 的 System.Net.NetworkInfomation
包中(该包是否存在?)。
根据package search website ,您需要添加对 System.Net.Utilities
包的引用。
关于c# - 找不到类型或命名空间名称 'Ping',尽管存在依赖关系和使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28449391/