Input string was not in a correct format.

Posted by Jon on Stack Overflow See other posts from Stack Overflow or by Jon
Published on 2010-04-30T14:33:55Z Indexed on 2010/04/30 14:37 UTC
Read the original article Hit count: 455

Filed under:

I have this error which doesn't happen on my local machine but it does when the code is built by our build sever and deployed to the target server.

I can't work out what the problem is, after having spent many hours on this issue.

Here is an error trace:

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7469351
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
   System.Byte.Parse(String s, NumberStyles style, NumberFormatInfo info) +35
   System.String.System.IConvertible.ToByte(IFormatProvider provider) +46
   System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider) +199
   System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges) +127
   System.Web.UI.WebControls.Parameter.GetValue(Object value, Boolean ignoreNullableTypeChanges) +66
   System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control) +285
   System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList) +251
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +476
   System.Web.UI.WebControls.SqlDataSource.Select(DataSourceSelectArguments arguments) +19
   Customer_NewTenancyList.BindReport(GridSortEventArgs e) +442
   Customer_NewTenancyList.Page_Load(Object sender, EventArgs e) +345
   System.Web.UI.Control.OnLoad(EventArgs e) +73
   baseRslpage.OnLoad(EventArgs e) +16
   System.Web.UI.Control.LoadRecursive() +52
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2170

Here is my own trace:

 Begin PreInit      
aspx.page   End PreInit 3.12888928620816E-05    0.000031
aspx.page   Begin Init  7.43111205474439E-05    0.000043
aspx.page   End Init    0.00122138428208054 0.001147
aspx.page   Begin InitComplete  0.00125379063540199 0.000032
aspx.page   End InitComplete    0.00127781603527823 0.000024
aspx.page   Begin PreLoad   0.00131022238859967 0.000032
aspx.page   End PreLoad 0.00133424778847591 0.000024
aspx.page   Begin Load  0.00135575890231859 0.000022
    Page_Load   0.00145996209015392 0.000104
    BindReport  0.0014856636807192  0.000026
    Parameters add start: 30/03/2010 30/04/2010 0.0015569017850034  0.000071
    Parameters add ended    0.00160048274291844 0.000044
    Trace 1 0.00162450814279468 0.000024
Unhandled Execution Error   
Input string was not in a correct format.
  at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
  at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
  at System.Byte.Parse(String s, NumberStyles style, NumberFormatInfo info)
  at System.String.System.IConvertible.ToByte(IFormatProvider provider)
  at System.Convert.ChangeType(Object value, TypeCode typeCode, IFormatProvider provider)
  at System.Web.UI.WebControls.Parameter.GetValue(Object value, String defaultValue, TypeCode type, Boolean convertEmptyStringToNull, Boolean ignoreNullableTypeChanges)
  at System.Web.UI.WebControls.Parameter.GetValue(Object value, Boolean ignoreNullableTypeChanges)
  at System.Web.UI.WebControls.ParameterCollection.GetValues(HttpContext context, Control control)
  at System.Web.UI.WebControls.SqlDataSourceView.InitializeParameters(DbCommand command, ParameterCollection parameters, IDictionary exclusionList)
  at System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments)
  at System.Web.UI.WebControls.SqlDataSource.Select(DataSourceSelectArguments arguments)
  at Customer_NewTenancyList.BindReport(GridSortEventArgs e)
  at Customer_NewTenancyList.Page_Load(Object sender, EventArgs e)
  at System.Web.UI.Control.OnLoad(EventArgs e)
  at baseRslpage.OnLoad(EventArgs e)
  at System.Web.UI.Control.LoadRecursive()
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

And here is my code:

    Trace.Warn("BindReport")
    Dim sds As New SqlDataSource

    sds.SelectCommand = "C_MYSTORED_PROC"
    sds.ConnectionString = ConfigurationManager.ConnectionStrings("connstring").ConnectionString
    sds.SelectCommandType = SqlDataSourceCommandType.StoredProcedure
    Trace.Warn(String.Format("Parameters add start: {0} {1}", dpFrom.Text, dpTo.Text))

    sds.SelectParameters.Add(New Parameter("FROMDATE", DbType.DateTime, dpFrom.Text))
    sds.SelectParameters.Add(New Parameter("TODATE", DbType.DateTime, dpTo.Text))

    Trace.Warn("Parameters add ended")

    Dim dv As DataView
    Dim dt As DataTable
    Trace.Warn("Trace 1")

    dv = sds.Select(New DataSourceSelectArguments())
    Trace.Warn("Trace 2")
    If e IsNot Nothing Then
        dv.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection)
        Trace.Warn("Trace 3")
    Else
        gvReport.CurrentSortColumnIndex = 0
        gvReport.Columns(0).SortDirection = "DESC"
        Trace.Warn("Trace 4")
    End If

    Trace.Warn("Trace 5")
    dt = dv.ToTable()
    Cache("NewTenancyList") = dt
    Trace.Warn("Trace 6")

    Trace.Warn("About to databind")
    gvReport.DataSource = dt
    gvReport.DataBind()
    Trace.Warn("Databinded")

What I don't understand and this is really weird, why does it work on my local machine but not on the live server? If i build the code on my local machine then copy over the complete \bin directory it works. If I pull the code from source safe, build then copy, I get this error.

It seems to choke after the line "dv = sds.Select(New DataSourceSelectArguments())" in the code.

© Stack Overflow or respective owner

Related posts about ASP.NET