0

I am reading IPaddress from xml file and I put it into IPaddress.parse() and then use it but it does not work. it says "An invalid IP address was specified." but when I write it manually it works.

why I cant use IP address after reading xml file. I tried to erase "white spaces" , it said samething again.

string ipadd; //take ip address from xml and use
 ...
 IPAddress ipaddre = IPAddress.Parse(ipadd); 
------------------------------
 IPAddress ipaddre = IPAddress.Parse("255.255.255.255")

why these are not giving same result?

5
  • 1
    What is the exact value of ipadd that's passed to IPAddress.Parse? Commented Oct 21, 2010 at 16:45
  • try to check what is actual value of ipadd in debug Commented Oct 21, 2010 at 16:46
  • I put value of ipadd to a label, it is same , both of them are 255.255.255.255 ... but I will try to debug and return back. Commented Oct 21, 2010 at 18:43
  • 1
    I think it has \n and \r characters , it makes error . thanks everyone :) Commented Oct 21, 2010 at 18:51
  • I think it has \n and \r characters +1 for that! I got this "An invalid IP address was specified." error when the IP address had a dodgy hidden trailing character, probably due to copy and pasting from somewhere else. Fixed by deleting and manually typing the IP address in again. Commented May 7, 2014 at 16:58

2 Answers 2

3

If ipadd == "255.255.255.255" then there should be nothing stopping that from working.

Obviously, though, ipadd != "255.255.255.255"

I would suggest debugging, setting a breakpoint, and inspecting the value of ipadd when you pass it to the IPAddress.Parse() method.

Sign up to request clarification or add additional context in comments.

Comments

0

On the assumption that ipadd = "255.255.255.2552", then only two possibilities exist:

1) An exception is being thrown on the parse, and therefore your compare is not happening, or 2) The method you are using to compare the two results is not appropriate.

I strongly suggest you add both statements and place a breakpoint on the next line, then you will see exactly what you are dealing with:

IPAddress ipaddreReal = IPAddress.Parse(ipadd);
IPAddress ipaddreFake = IPAddress.Parse("255.255.255.255");
bool result = ipAddre.Real.Equals(ipaddreFake);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.