system.net.ipaddress.parse

I've searched everywhere and tried it on two computers, and I'm completely stumped on this one.

I'm using VB Express Edition with .net 2.0 on Windows XP SP2 attempting to create a simple telnet client. According to the documentation and all the web searches I've found, the correct way to connect to a (named) internet server is to use system.net.ipaddress.parse("theaddress.com") which returns an ipaddress I can then combine with a port and use to open a socket connection to the server.

The problem is that I get an error saying that the .parse method is undefined, and so my code (which I believe is otherwise correct) doesn't compile. Is this a disabled feature in VB Express Or is it deprecated in the current version of .net If so, what is the replacement/workaround for this feature

Thanks in advance for your help.


Answer this question

system.net.ipaddress.parse

  • TechCzech

     

    I've always found that the specifiying namespace.class usually does suffice.

    BUT I've also learned that when there are things that you KNOW are there and are not defined then an import will help at times. I've found this is be especially true with intellisense.

    When you have questions along these lines, I really recommend the unsung heroine of VS2005 which is the object browser. It's wonderful for chasing these things down and it's fast.

    Renee



  • Mario02

    There's a difference between importing a Namespace and a class. By using:

    Imports System.Net.IPAddress

    You are importing a class and can call the parse method of that class because it is static (you don't need an instance of that class to call the parse method), as I understand it. Thus you can call:

    addr = Parse("127.0.0.1")

    But:

    addr = System.Net.IPAddress.Parse("127.0.0.1")

    Should work (and does) without the Imports declaration, so I'm not sure what's going on with your system, and was posting the above as possibly a helpful pointer.

    Do you get the problem in a brand new project It's possible that the project you have may have some kind of namespace conflict



  • Beav1810

    From time to time... with rare classes, I've noticed strangenesses that I really didn't understand.

    When I see strangenesses especially where things are not defined, an Imports doesn't hurt and fixes the problem 80 percent of the time.



  • eduboys

    Imports System.Net.IPAddress

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim a As System.Net.IPAddress

    a = System.Net.IPAddress.Parse("0.0.0.0")

    End Sub

    This works for me



  • Patrick Blair

    I think I see the problem. Making a fresh clean VB Windows Application project, and typing in:

    Dim a As System.Net.IPAddress

    a = System.Net.IPAddress.Parse("0.0.0.0")


    Works for me at work, where I have both Visual C++ Express and Visual Basic Express installed. But it doesn't work for me at home where I have only Visual Basic Express installed.

    I'll try re-installing it at home, maybe it's as simple as a corrupted download.

    In the meantime, the workaround Renee posted works both at home and at work, so I should be able to use that without any problems. Thanks for the help.


  • _ _

    Thanks for the tip, I actually did use the class browser (which is how I found parse in the first place-- well, along with Google), but the problem is that it doesn't, as far as I can tell, tell me whether the method requires me to use import or not. Or is there something I'm missing

    For the curious, I'm coming from a RealBasic, C++, and Cocoa background-- I've never used VB before.

  • Tarun Makhija

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim a As System.Net.IPAddress

    a = System.Net.IPAddress.Parse("0.0.0.0")

    End Sub

    This compiles and executes cleanly on my system Notice No Import statement...... This is a New Trivial Project... As for rules.... It Deals with OOP - Scope, inheridence, Etc...... It's all Greek to me... Take a look at Imports in Help


  • Kees van der Oord

    Thanks for your help, but I'm not really satisfied with that answer.

    This entire .net environment is designed, so there must be some design reason why you need to use "import" and when you don't. Is it possible that someone with more knowledge of that reason is reading this and could post It'll save me tons of time in the future if I know the rule, thanks. (No offense, Renee.)

  • KevinUT

    The only difference between your code and mine is the "imports" line. Is this always required to use methods like this I was under the impression that if you spelled out the entire class path (system.net.ipaddress.parse) you didn't need to use the "imports" command.

    Thanks for your help, it does work.

  • system.net.ipaddress.parse