title: How do I represent URNs (Uniform Resource Names) in .NET so that Equals works as expected
body: <p><a href="https://www.rfc-editor.org/rfc/rfc2141" rel="nofollow noreferrer">RFC2141</a> mentions:</p>
  <blockquote>
  <ol start="6">
  <li><p>Examples of lexical equivalence</p>
  <p>The following URN comparisons highlight the lexical equivalence<br />
  definitions:</p>
  <pre><code>    1- URN:foo:a123,456
      2- urn:foo:a123,456
      3- urn:FOO:a123,456
      4- urn:foo:A123,456
      5- urn:foo:a123%2C456
      6- URN:FOO:a123%2c456
  </code></pre>
  <p>URNs 1, 2, and 3 are all lexically equivalent.</p>
  </li>
  </ol>
  </blockquote>
  <p>The subsequent <a href="https://www.rfc-editor.org/rfc/rfc8141" rel="nofollow noreferrer">RFC8141</a> preserves that equivalence:</p>
  <blockquote>
  <p>2.1.  Namespace Identifier (NID)</p>
  <p>NIDs are case insensitive (e.g., &quot;ISBN&quot; and &quot;isbn&quot; are equivalent).</p>
  </blockquote>
  <p>The closest representation for a URN that I could easily find in the .NET framework is the <a href="https://docs.microsoft.com/en-us/dotnet/api/system.uri" rel="nofollow noreferrer">URI class</a>. However, it does not seem to fully respect the RFC definition of equivalence:</p>
  <pre><code>    [TestMethod]
      public void TestEquivalentUrnsAreBroken()
      {
          Assert.AreEqual(
              new Uri(&quot;URN:foo:a123,456&quot;),
              new Uri(&quot;urn:foo:a123,456&quot;));
  
          Assert.AreEqual(
              new Uri(&quot;urn:foo:a123,456&quot;),
              new Uri(&quot;urn:FOO:a123,456&quot;));
      }
  </code></pre>
  <p>In the code example above the first assert works as expected, whereas the second assert fails.</p>
  <p>Is there any reasonable way to get the URI class to respect the equivalence definition? Is there any other class I should be using instead?</p>
  <p>Please note that I have found the <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.sqlserver.management.sdk.sfc.urn" rel="nofollow noreferrer">URN class</a>, but the documentation mentions that it should not be used directly.</p>