Why,Ping functionality is not supported in UWP platform.

Avnish Kumar 31 Reputation points
2020-04-19T12:08:22.627+00:00

I added the System.Net.Ping NuGet Package to a blank UWP project and referenced the System.Net.NetworkInformationnamespace.

Ping ping = new Ping();
var rep = await ping.SendPingAsync("8.8.8.8");

Inner Exception:
PlatformNotSupportedException: Ping functionality is not currently supported in UWP.

Developer technologies | Universal Windows Platform (UWP)
0 comments No comments
{count} vote

Accepted answer
  1. Peter Smith 581 Reputation points Microsoft Employee
    2020-04-21T21:50:41.173+00:00

    I can't give a short answer, because it would be super controversial. But I can give you a good long answer.

    Firstly, to bring everyone reading this up to speed: Ping is a very specific network protocol. You might think it's a UDP or maybe TCP based thing, but it's not: Ping is based on ICMP, a set of messages designed for communications between routers. Specifically, PING is built around the ECHO ICMP message (message type #8, and the reply is message type #0). Other ICMP messages are things like type #11, "Time Exceeded" (sent when a packet comes in with no time remaining), or type #4, "Source Quench" used when there's too much data coming in.

    Fun historical diversion: in the original design of the internet, the idea is that each site (with possibly multiple real computers) would connect to the "internet message processor" (IMP); the imps were then connected together via phone lines. The ICMP messages were designed to go between the IMPs and not between the actual computers. Many IMPs also have a dedicated teletypewriter connected to the imp. So there's networking protocols designed for programs to use to connect to programs, and other network protocols designed just for the networking hardware.

    So right away there's a problem: the PING message is unlike every other type of packet that the network codes uses. It's not TCP, it's not UDP, it's not a higher level protocol like ATOM or RSS or HTTP that we might want to support. Adding PING support would actually have required work.

    The second problem is that PING is (no offense) somewhat overrated. Yes, it's often used to tell if a remote server is up. On the other hand, ICMP messages are routinely suppressed by firewalls, aren't routed by routers, and dropped entirely going in and out of a data center. Worse, a server can be effectively dead for use, and yet because of where PING is handled, it's still sending out replies.

    This means that if you rely on PING to determine that a server is unreachable or dead, you'll have a bad time: there are plenty of cases where the server is perfectly fine and usable, but PING won't find it. And the flip side is true: just because PING can connect to the server, it doesn't mean that the server will actually talk to you.

    The general network programming recommendation is: just try to connect to the server. If it fails, then you know it failed. If it works, you know it works. But trying to guess from PING if a server if OK isn't nearly as effective as you want it to be.

    Source: I was the program manager (PM) on the team at Microsoft that decided to not support PING in UWP apps.

    3 people found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. Craig Mitchell 6 Reputation points
    2021-06-06T18:38:43.167+00:00

    It would be great if Microsoft align these desktop UI frameworks.

    I was able to quite easily make a WPF app use ping (ICMP), as soon as I tried to convert the app to UWP I received this exception:

    System.Net.NetworkInformation.PingException: 'An exception occurred during a Ping request.'
    Inner Exception: PlatformNotSupportedException: Ping functionality is not currently supported in UWP.

    I appreciate pesmith's response and understand we can't always have everything we want, but still having API alignment between the desktop UI frameworks would be great :)

    1 person found this answer helpful.
    0 comments No comments

  2. Shay Wilner 1,746 Reputation points
    2020-04-19T18:53:17.83+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.