It blew my mind when I found that Uri tostring breaks uris…. Here is an example
If you run this in immediate mode you’d get
new Uri("http://site.com?a=1&b=c%26d").AbsoluteUri
Res
"http://site.com/?a=1&b=c%26d"
But
new Uri("http://site.com?a=1&b=c%26d").ToString() //string.format i believe doesn't need .ToString()
Gets me
"http://site.com/?a=1&b=c&d"
The b value is completely broken. I was shocked. Am I never to use ToString()? This seems like a bug. But writing this question gave me the answer (.AbsoluteUri). But maybe this will help someone.
The
Uri.ToStringmethod isn’t useful for anything other than to display the URI in a human friendly way.From the code example on the documentation for Uri.ToString:
The example shows that the
ToStringmethod returns a string with spaces, which is not a character that is valid in an URI. The string representation of the Uri is clearly not intended to be used as an actual URI. This fact should perhaps be made more clearly in the documentation.