Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
674 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...