1.73.0 (latest) 1.69.0 1.68.0 1.60.0 1.59.0 1.55.0 1.50.0

    public static class UriPatcher

Workarounds for some unfortunate behaviors in the .NET Framework's
implementation of System.Uri

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> UriPatcher

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Apis.Util](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.md.txt)

## Assembly

Google.Apis.Core.dll

## Remarks

UriPatcher lets us work around some unfortunate behaviors in the .NET Framework's
implementation of System.Uri.

== Problem 1: Slashes and dots

Prior to .NET 4.5, System.Uri would always unescape "%2f" ("/") and "%5c" ("\\").
Relative path components were also compressed.

As a result, this: "<http://www.example.com/.%2f.%5c./>"
... turned into this: "<http://www.example.com/>"

This breaks API requests where slashes or dots appear in path parameters. Such requests
arise, for example, when these characters appear in the name of a GCS object.

== Problem 2: Fewer unreserved characters

Unless IDN/IRI parsing is enabled -- which it is not, by default, prior to .NET 4.5 --
Uri.EscapeDataString uses the set of "unreserved" characters from RFC 2396 instead of the
newer, *smaller* list from RFC 3986. We build requests using URI templating as described
by RFC 6570, which specifies that the latter definition (RFC 3986) should be used.

This breaks API requests with parameters including any of: !\*'()

== Solutions

Though the default behaviors changed in .NET 4.5, these "quirks" remain for compatibility
unless the application explicitly targets the new runtime. Usually, that means adding a
TargetFrameworkAttribute to the entry assembly.

Applications running on .NET 4.0 or later can also set "DontUnescapePathDotsAndSlashes"
and enable IDN/IRI parsing using app.config or web.config.

As a class library, we can't control app.config or the entry assembly, so we can't take
either approach. Instead, we resort to reflection trickery to try to solve these problems
if we detect they exist. Sorry.

## Methods

### PatchUriQuirks()

    public static void PatchUriQuirks()

Patch URI quirks in System.Uri. See class summary for details.