title: InvalidCastException from C# back-end
body: <p>I'm receiving different behavior form local environment to development environment due to Invalid casting of DateTimeOffset related issues. Strangely enough the same web application is also in test environment and is working without error.  The only place I'm receiving the error is in development, but no in test or in my local computer. </p>
  
  <p>Error I'm receiving:</p>
  
  <pre><code> [InvalidCastException: Specified cast is not valid.]
     System.Data.SqlClient.SqlBuffer.get_DateTime() +6531011
     System.Data.SqlClient.SqlDataReader.GetDateTime(Int32 i) +61
     G_C.G_C_CodeGroupData.ReadDBRowForMaint() +765
     G_C.G_C_CodeGroupEdit.OnInit(EventArgs e) +341
     System.Web.UI.Control.InitRecursive(Control namingContainer) +186
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2098
  </code></pre>
  
  <p>From C# code I'm calling a stored procedure that is retrieving data from columns this way:</p>
  
  <pre><code>dr.GetDateTimeOffset(4).ToLocalTime().DateTime.ToString()
  </code></pre>
  
  <p>On the other hand, the stored procedure is just a select statement selecting records based on the id.  </p>
  
  <p>The column definitions for that specific column is :</p>
  
  <pre><code>[VAR_CREATE_DATE] [datetimeoffset](7) NULL CONSTRAINT [DF_G_C_CODE_VARIABLE_VAR_CREATE_DATE]  DEFAULT (sysdatetimeoffset()),
  </code></pre>
  
  <p>There's might be a very explicit reason why I can't get rid of this error, but it is escaping me at this moment. I can't see where the error is; or what is triggering it. </p>
  
  <p>PS. Local and Test environment are looking to the same database and table definitions.</p>
  
  <p>Thank you,
  N. </p>