0

I am making a windows phone 7 application in c#, visual studio 2012 and it needs to check if internet connection is available in the device before sending some request.

Initially I was trying to use

NetworkInterface.GetIsNetworkAvailable()

but it always returned true.I found a solution here. But I am now having problem with that also.

I wrote the following code(after using System.Net ) Code

    private bool checkInternet()
    {
        try
        {
            IPHostEntry _hostEntry = Dns.GetHostEntry("www.google.com");
            return true;
        }
        catch(SocketException _err){
            return false;
        }
    }

But it didn't compile and gave the following error Error_Image

Error 1 The type or namespace name 'IPHostEntry' could not be found (are you missing a using directive or an assembly reference?)

Community
  • 1
  • 1
bytestorm
  • 1,411
  • 3
  • 20
  • 36

2 Answers2

0

Let me ask you a very deep question:

are you missing a using directive?

This is a quote from the error message, and following up on it resolves your problem. I encourage you to do some research what a using directive is and what they mean in the C# language.

usr
  • 168,620
  • 35
  • 240
  • 369
  • This is all the directives I have included -- [Code](http://i.stack.imgur.com/au8rn.png)... Please help me out, I don't see what is the problem here – bytestorm Nov 02 '13 at 14:33
  • Please also show a screenshot that you referenced the appropriate assembly. – usr Nov 02 '13 at 14:38
  • Why is `system` with lowercase-s? Remove the reference and add it back. Not sure what you got there. – usr Nov 02 '13 at 14:57
  • I added the System back with uppercase 'S' but with no effect. – bytestorm Nov 03 '13 at 02:17
0

As documented here, you must use the

System.Net.NetworkInformation

namespace

which implements the NetworkInterface and provides your method.

Regis Portalez
  • 4,675
  • 1
  • 29
  • 41