-1

AFAIK anything up to 2000 characters ought to be supported.

Reproduction:

var s = "http://www."
+ string.Join("", Enumerable.Repeat("a", 249))
+ ".com";

new Uri(s, UriKind.Absolute);

One letter shorter one is being parsed with no issue:

var s = "http://www."
+ string.Join("", Enumerable.Repeat("a", 248))
+ ".com";

The Uri class code was originated in 2003 and is carried over to .net standard / core. Does MS still claim 255 characters for path / URI is enough for everybody's needs?

haim770
  • 48,394
  • 7
  • 105
  • 133
grzegorz_p
  • 483
  • 1
  • 4
  • 14

1 Answers1

5

You're trying to create an Uri with a hostname of more than 255 characters. 255 is the max.

This is also reflected in the exception message:

Invalid URI: The hostname could not be parsed.

So this one is not to blame on Microsoft.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • I intended the words "exception message" to link to [this ideone repro](https://www.ideone.com/mRmM5O) that includes the exception message, but the system won't let me because then I'll have to repeat the OP's code. – CodeCaster May 07 '18 at 14:50