0

I am using an HttpClient in Dotnet 5 and try to create a query with a very long URI. I get this exception

Invalid URI: The uri string is too long

I tried to figure out where it comes from and it seems it boils down to this line with a constant:

internal const int c_MaxUriBufferSize = 0xFFF0;

It seems that it is actually impossible to have a URL longer than 64K, but there is perhaps something I did not figure out?

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207

1 Answers1

1

In short: you can't.

If you look at the source of Uri then it becomes clear why.

  • In case of .NET Core the Uri's source code resides in this file.

Inside its GetException method it translates ParsingError.SizeLimit into an UriFormatException.

  • The related resource entry can be found here.

So, if we look at the code of the Uri to see when it fails with ParsingError.SizeLimit then we will find these:

In the first two cases the limit is checked against c_MaxUriBufferSize (1), which is defined as this:

internal const int c_MaxUriBufferSize = 0xFFF0;

In later cases the limit is checked against ushort.MaxValue.

Unfortunately none of them are changeable.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75