【问题标题】:The type or namespace name 'Ping' could not be found, although there is a dependencie and a using找不到类型或命名空间名称“Ping”,尽管存在依赖项和 using
【发布时间】:2015-04-11 12:45:02
【问题描述】:

我正在创建一个小程序来 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();   
        }

    }
}

尝试编译此代码时的完整错误是:

代码:错误 CS0246 说明:类型或命名空间名称“Ping”可能 找不到(您是否缺少 using 指令或程序集 参考?)项目:TestApp.ASP.NET Core 5.0 文件:Program.cs 行:9

【问题讨论】:

    标签: c# asp.net-core console-application ping


    【解决方案1】:

    问题是 Ping 不在 CoreCLR (aspnetcore50) 的 System.Net.NetworkInfomation 包中(那个包甚至存在吗?)。

    根据package search website,需要添加对System.Net.Utilities包的引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-12
      • 2011-05-13
      • 2013-03-25
      • 2012-06-19
      • 2017-11-29
      相关资源
      最近更新 更多