Bug 2926 - DataTable.ImportRow causes InvalidCastException
Summary: DataTable.ImportRow causes InvalidCastException
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data ()
Version: 2.10.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Rolf Bjarne Kvinge [MSFT]
Depends on:
Reported: 2012-01-16 22:17 UTC by Dominique NORMAND
Modified: 2012-01-17 17:22 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Dominique NORMAND 2012-01-16 22:17:17 UTC
When importing a row from a table to another one, if the source column data type is not string and the destination column data type is string we end-up with InvalidCastException in StringDataContainer.DoCompareValues

Here how to reproduce it:

DataSet 	ds = new DataSet() ;
DataTable	dt1 = ds.Tables.Add("T1");
DataTable	dt2 = ds.Tables.Add("T2");

dt1.Columns.Add("C1", typeof(decimal));
dt1.Columns.Add("C2", typeof(decimal));

dt2.Columns.Add("C1", typeof(string)) ;
dt2.Columns.Add("C2", typeof(decimal));

DataRow row = dt1.NewRow();

row["C1"] = 12345 ;
row["C1"] = 67890 ;

dt2.ImportRow(row) ;
dt2.Rows[0]["C2"] = 22 ; // This will cause the exception
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-01-17 17:22:55 UTC
Fixed (master: 656ca1172, 2.10: bd747ae20, mobile-master: ff12be65).