Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
670 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...