title: Uri.TryCreate throws UriFormatException?
body: <p>I have a method that tries to create a Uri and then clean it up (removes fragments, excludes some domains and query string patterns, etc.).  The method looks like this:</p>
  
  <pre><code>static public bool TryCreateCleanUri(Uri baseUri, string relstr, out Uri result)
  {
      if (!Uri.TryCreate(baseUri, relstr, out result))
      {
          return false;
      }
      return CleanupUri(result, out result);
  }
  </code></pre>
  
  <p>This method has been working fine for months.  But last night it failed.  Uri.TryCreate() threw an exception!  Here's the stack trace:</p>
  
  <pre><code>ERROR: Unhandled exception caught.  Program terminating.
  System.UriFormatException: Invalid URI: The hostname could not be parsed.
     at System.Uri.CreateHostStringHelper(String str, UInt16 idx, UInt16 end, Flags&amp; flags, String&amp; scopeId)
     at System.Uri.CreateHostString()
     at System.Uri.GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat)
     at System.Uri.CombineUri(Uri basePart, String relativePart, UriFormat uriFormat)
     at System.Uri.GetCombinedString(Uri baseUri, String relativeStr, Boolean dontEscape, String&amp; result)
     at System.Uri.ResolveHelper(Uri baseUri, Uri relativeUri, String&amp; newUriString, Boolean&amp; userEscaped, UriFormatException&amp; e)
     at System.Uri.TryCreate(Uri baseUri, Uri relativeUri, Uri&amp; result)
     at System.Uri.TryCreate(Uri baseUri, String relativeUri, Uri&amp; result)
  </code></pre>
  
  <p>Documentation for <code>Uri.TryCreate(Uri, String, out Uri)</code> says that the return value is <code>True</code> if successful, <code>False</code> otherwise, but it's silent about exceptions.  However, documentation for <code>Uri.TryCreate(Uri, Uri, out Uri)</code> says:</p>
  
  <blockquote>
    <p>This method constructs the URI, puts
    it in canonical form, and validates
    it. If an unhandled exception occurs,
    this method catches it. If you want to
    create a Uri and get exceptions use
    one of the Uri constructors.</p>
  </blockquote>
  
  <p>The stack trace shows that the exception was thrown in <code>Uri.TryCreate(Uri, Uri, out Uri)</code>, which, according to the documentation, shouldn't happen.</p>
  
  <p>This is a very rare occurrence.  I've been using that code for months, running literally billions of urls through it, and haven't encountered a problem until now.  Unfortunately I don't know what combination of things caused the problem.  I'm hoping to construct a test case that shows the error.</p>
  
  <p>Is this a known bug in <code>Uri.TryCreate</code>, or am I missing something?</p>