I want to serial a hash table using the link
But I'm getting the error
Type 'WpfApplication3.MyHashtable' with the data contract name 'All mashashtable': 'Not expected. The list of known types is not known in any type of known type - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types near the DataContractSerializer.
My program is
Namespace WpfApplication3 // & lt; Summary & gt; /// Window 1. Interaction logic for xaml /// & lt; / Summary & gt; Public Partial Segment Window 1: Window {Public Window 1 () {Initial Group (); } Private Zero Button 1_Click (Object Sender, RoutedEventArgs e) {MyHashtable ht = new MyHashtable (); Date time DT = Date time.Now; For (int i = 0; i & lt; 10; i ++) ht.Add (dt.AddDays (i), i); SerialJet XMLFile (typef (hashtable), HT); } Private Zero SerializeToXmlAsFile (type targetType, Object targetObject) {try {string fileName = @ "C: \ output.xml"; DataContractSerializer S = New Data Contributoriserizer (Target Type); XmlWriterSettings Settings = New XmlWriterSettings (); Settings.Indent = true; Settings. Indent Chase = (""); (Xmlrr w = XmlWriter.Create (using filename, settings) {s.WriteObject (w, targetObject); W.flush (); }} Hold (Exception pre) {east; }}} [Collected data contract (name = "all mashsheet", item name = "myintree", keyname = "modet", value name = "myvalue")) public class mahoutable: dictionary & lt; DateTime, Int & gt; {}} What is wrong ..
thanks
Error getting because the line is happening:
SerializeToXmlAsFile (typef (hashtable), HT);
In your button 1_Click method, you are going through the Hashtable type DataContractSerializer constructor starts to serial itself to serialize the type of object you specify, in this case the hashtable Consequently, when you pass a type of MyIgatabat object when you call it
s.WriteObject (w, targetObject);
This does not know how to process it. To do this work, change what you have to do:
SerializeToXmlAsFile (typeof (MyHashtable), HT);
Comments
Post a Comment