title: How to resolve the Dapper System.Data.DataException HResult=0x80131501 InvalidCastException Invalid cast from 'System.String' to 'System.Uri'
body: <p>Recently, I refactored some code which resulted in changing the type of some properties of an entity from <code>System.String</code> to <code>System.URI</code>. The names of the properties in question contained the substring URI or URL and the <a href="https://www.sonarlint.org/" rel="noreferrer">SonarLint</a> static code analyzer was recommending that the code be refactored to use the <code>System.URI</code> type instead of <code>System.String</code> for those properties, which makes sense in our solution.</p>
  
  <p>In this project, we are leveraging StackExchange's <a href="https://github.com/StackExchange/Dapper" rel="noreferrer">Dapper</a> as an ultra fast and light object mapper, but after the refactoring, I started receiving this error when trying to retrieve data from my repository:</p>
  
  <pre><code>System.Data.DataException
    HResult=0x80131501
    Message=Error parsing column 5 (RequestUrl=https://www.myurl.com/api/wow - String)
    Source=Dapper
    StackTrace:
     at Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value) in C:\projects\dapper\Dapper\SqlMapper.cs:line 3609
     at Dapper.SqlMapper.&lt;&gt;c__DisplayClass156_0`8.&lt;GenerateMapper&gt;b__1(IDataReader r) in C:\projects\dapper\Dapper\SqlMapper.cs:line 1544
     at Dapper.SqlMapper.&lt;MultiMapImpl&gt;d__153`8.MoveNext() in C:\projects\dapper\Dapper\SqlMapper.cs:line 1444
     at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
     at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
     at Dapper.SqlMapper.&lt;MultiMapAsync&gt;d__52`8.MoveNext() in C:\projects\dapper\Dapper\SqlMapper.Async.cs:line 949
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     at My.Namespace.MyRepository.&lt;GetAllRepositoryMethod&gt;d__2.MoveNext() in C:\dev\repos\myproject\MyRepository.cs:line 59
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at My.Namespace.Program.CallerMethod(Object sender, ElapsedEventArgs e) in C:\dev\repos\myproject\Program.cs:line 109
     at System.Timers.Timer.MyTimerCallback(Object state)
  
  Inner Exception 1:
  InvalidCastException: Invalid cast from 'System.String' to 'System.Uri'.
  </code></pre>
  
  <p>How can I get around this error?</p>