Convert long to System.Int64 throws error?
<p>I got a strange error that got me buffeled:
I have a function ..uhm... something like this:</p>

<pre><code>void someFunctionTakingALong( long ID)
{
  var table = new DataTable();
  table .Columns.Add(new DataColumn("RID", Type.GetType("System.Int64")));
  table.Rows.Add(ID);       //&lt;-- throws err
}
</code></pre>

<p>throws this error:</p>

<pre><code>System.ArgumentException: Input string was not in a correct format.Couldn't store  in RID Column.  Expected type is Int64. ---&gt; System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&amp; number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt64(String value, NumberStyles options, NumberFormatInfo numfmt)
   at System.String.System.IConvertible.ToInt64(IFormatProvider provider)
   at System.Data.Common.Int64Storage.Set(Int32 record, Object value)
   at System.Data.DataColumn.set_Item(Int32 record, Object value)
   --- End of inner exception stack trace ---
</code></pre>

<p>This happens in production, and I don't have logs to see what value of ID is actually passed to the function... but even so.. having the parameter a long should AT LEAST guarantee that ID is a long ... right? So why is this throwing? What values could ID have that are not convertible to a int64 ?</p>

<p><strong>EDIT:</strong></p>

<p>Here is the actual source : Trhowing column is <strong>PropValueID</strong></p>

<pre><code>public void AddRule(int PropID, long PropValueID, int type, string Data)
        {
            if (!m_HasRule)
            {
                m_Rules = new DataTable();
                m_Rules.Columns.Add(new DataColumn("RID", Type.GetType("System.Int32")));
                m_Rules.Columns.Add(new DataColumn("PropID", Type.GetType("System.Int32")));
                m_Rules.Columns.Add(new DataColumn("PropValueID", Type.GetType("System.Int64")));
                //m_Rules.Columns.Add(new DataColumn("PropValue", Type.GetType("System.String")));
                m_Rules.Columns.Add(new DataColumn("Type", Type.GetType("System.Int32")));
                m_Rules.Columns.Add(new DataColumn("Data", Type.GetType("System.String")));
                m_HasRule = true;
            }
            ToStringSB = null;

            if (type&lt;2)  // a "Is/Not specified property"
            {            
                if (string.IsNullOrEmpty(Data)) //is specified (0,1)
                   m_Rules.Rows.Add(m_RID, PropID, 0, type, "");       //&lt;&lt;-- here we pass 0 (int32) instead of long.. could this be it? Stack says this is not the line throwing
                else  //is equal to/is not equal to(2,3) 
                    m_Rules.Rows.Add(m_RID, PropID, PropValueID,3-type, Data);                
            }else
                if ((type &gt; 3) &amp;&amp; (type &lt; 6)) // a "like/not like" rule
                {
                    // "Like" or "not like" DATA .. no value ID is provided
                    m_Rules.Rows.Add(m_RID, PropID, PropValueID, type, Data); //&lt;&lt;-- Stack says it throws here 

                }
                else // a greater/lesser rule
                {
                    m_Rules.Rows.Add(m_RID, PropID, PropValueID, type, Data);
                }

        } 
</code></pre>

<p>There is a suspect line where we pass on literal 0 (an int) but that's not the line number where the stack says it throws.</p>
