The type or namespace name 'Ping' could not be found, although there is a dependencie and a using

倾然丶 夕夏残阳落幕 提交于 2019-11-28 06:32:29

问题


I am creating a little program to ping a computer within a network. For this i am trying to use the class ping, from

namespace System.Net.NetworkInformation.Ping

I am using ASP.NET 5.0 so i hava project.json file with my dependecies

  {
    "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"


            }
        }
    }
}

A simplefied version of the console code witch still gives the error is:

using System.Net.NetworkInformation;
namespace TestApp
{
    public class Program
    {

        public static void Main(string[] args)
        {
            Ping p = new Ping();   
        }

    }
}

the complete error when trying to compile this code is:

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


回答1:


The problem is that Ping is not in the System.Net.NetworkInfomation package (does that package even exist?) for CoreCLR (aspnetcore50).

According to the package search website, you need to add a reference to the System.Net.Utilities package.



来源:https://stackoverflow.com/questions/28449391/the-type-or-namespace-name-ping-could-not-be-found-although-there-is-a-depend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!