title: Input string was not in a correct format when using WebUtility.UrlEncode
body: <p>I'm been getting an exception from <a href="http://msdn.microsoft.com/en-us/library/system.net.webutility.urlencode.aspx?cs-save-lang=1&amp;cs-lang=csharp#code-snippet-1" rel="nofollow">WebUtility</a> and I'm not sure why (although I suspect it's something simple my caffeine deprived brain is missing). The documentation states it expects UTF-8, so I did a conversion and still no love: </p>
  
  <pre><code>Unhandled Exception: System.FormatException: Input string was not in a correct format.
     at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
     at System.String.Format(IFormatProvider provider, String format, Object[] args)
     at System.IO.TextWriter.WriteLine(String format, Object arg0)
     at System.IO.TextWriter.SyncTextWriter.WriteLine(String format, Object arg0)
     at System.Console.WriteLine(String format, Object arg0)
     at testApp.Program.Main(String[] args) in c:\Users\roberth\Programming_Projects\VisualStudio\testApp\testApp\Program.cs:line 18
  </code></pre>
  
  <p>Here is a sample program: </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Net;    
  
  namespace testApp
  {
      class Program
      {
          static void Main(string[] args)
          {         
              String url = "This is a URL to Encode%!";
              Byte[] bytes = Encoding.Default.GetBytes(url.ToCharArray());
              String utfUrl = Encoding.UTF8.GetString(bytes);
  
              Console.WriteLine(utfUrl);
              Console.WriteLine("Encoded: {}", WebUtility.UrlEncode(utfUrl));
              Console.WriteLine("Decoded: {}", WebUtility.UrlDecode(utfUrl));
          }
      }
  }
  </code></pre>