diff --git a/src/System.Data.Common/src/System/Data/DataTable.cs b/src/System.Data.Common/src/System/Data/DataTable.cs index 7da6e969c231..8ffc38539ade 100644 --- a/src/System.Data.Common/src/System/Data/DataTable.cs +++ b/src/System.Data.Common/src/System/Data/DataTable.cs @@ -372,8 +372,7 @@ internal void SerializeTableSchema(SerializationInfo info, StreamingContext cont info.AddValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.DefaultValue", i), Columns[i].DefaultValue); info.AddValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.ReadOnly", i), Columns[i].ReadOnly); info.AddValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.MaxLength", i), Columns[i].MaxLength); - info.AddValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.DataType", i), Columns[i].DataType); - + info.AddValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.DataType_AssemblyQualifiedName", i), Columns[i].DataType.AssemblyQualifiedName); info.AddValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.XmlDataType", i), Columns[i].XmlDataType); info.AddValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.SimpleType", i), Columns[i].SimpleType); @@ -442,7 +441,8 @@ internal void DeserializeTableSchema(SerializationInfo info, StreamingContext co dc._columnUri = info.GetString(string.Format(formatProvider, "DataTable.DataColumn_{0}.Namespace", i)); dc.Prefix = info.GetString(string.Format(formatProvider, "DataTable.DataColumn_{0}.Prefix", i)); - dc.DataType = (Type)info.GetValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.DataType", i), typeof(Type)); + string typeName = (string)info.GetValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.DataType_AssemblyQualifiedName", i), typeof(string)); + dc.DataType = Type.GetType(typeName, throwOnError: true); dc.XmlDataType = (string)info.GetValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.XmlDataType", i), typeof(string)); dc.SimpleType = (SimpleType)info.GetValue(string.Format(formatProvider, "DataTable.DataColumn_{0}.SimpleType", i), typeof(SimpleType)); diff --git a/src/System.Data.Common/tests/System/Data/DataTableTest.cs b/src/System.Data.Common/tests/System/Data/DataTableTest.cs index 92f507d88a8a..605b1e1b801c 100644 --- a/src/System.Data.Common/tests/System/Data/DataTableTest.cs +++ b/src/System.Data.Common/tests/System/Data/DataTableTest.cs @@ -32,6 +32,7 @@ using System.Diagnostics; using System.Globalization; using System.IO; +using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Tests; using System.Xml; using Xunit; @@ -388,6 +389,25 @@ public void SelectOperators() } + [Fact] + public void DataColumnTypeSerialization() + { + DataTable dt = new DataTable("MyTable"); + DataColumn dc = new DataColumn("dc", typeof(int)); + dt.Columns.Add(dc); + dt.RemotingFormat = SerializationFormat.Binary; + + DataTable dtDeserialized; + using (MemoryStream ms = new MemoryStream()) + { + BinaryFormatter bf = new BinaryFormatter(); + bf.Serialize(ms, dt); + ms.Seek(0, SeekOrigin.Begin); + dtDeserialized = (DataTable)bf.Deserialize(ms); + } + Assert.Equal(dc.DataType, dtDeserialized.Columns[0].DataType); + } + [Fact] public void SelectExceptions() {