.net - Serializing in C# not serializing a List when there is a DataTable on the side? -
Here is my code:
[Serializable ()] public class Project {private List From & lt; String & gt; _Kinds = New list & lt; String & gt; (); Public datable extracted elementtable; Public Project () {ExtractedElementsTable = New DataTable (); ExtractedElementsTable.TableName = "Output"; } Public listing & lt; String & gt; Type ({return _ key;} set {_Kinds = value;}}}
, After adding the list & lt some stuff, string & gt; _Kinds
my whole poject
try to serialize and then deserialize it, _Kinds
list is empty. but if I comment out all three lines where ExtractedElementsTable
is referred to, it works fine. here's my serializing and deserializing code (Please note currentProject.Kinds.Add ( "Hi") is, .. line serializing code
currentProject
bus project The example
private void openButton_Click (object sender, EventArgs e) {if (openFileDialog1.ShowDialog () == DialogResult.OK) {Stream stream = File.Open (openFileDialog1.FileName, FileMode .Open); XmlSerializer xmlFormatter = new XmlSerializer (currentProject.GetType ()); currentProject = (project) xmlFormatter.Deserialize (stream); stream.Close ();}} private void saveButton_Click (object sender, EventArgs e) {if ( SaveFileDialog1.ShowDialog () == DialogResult.OK) {currentProject.Kinds.Add ("Hi"); Stream stream = File.Open (saveFileDialog1.FileName, FileMode.Create); XmlSerializer xmlFormatter = New XmlSerializer (currentProject.GetType ()); XmlFor case Serial (current, current projection); Stream.Close (); }}
Change the DataTable field for a dataset area. I run some tests. Type of property is sorted with all the objects. But do not deserialize properly, however, I changed the DataTable field to a dataset and it all worked fine.
Comments
Post a Comment