wyidvrqhpk
New Member
I seem to be having problems with XmlSerializer.The error is as follows:\[code\]System.invalidOperationException: There is an error in XML cotument(2,2), ---> System.invalidOperationException: <Translator xmlns="> was not expected\[/code\]My XMLSerializer code is:\[code\]public static class XmlSerializerHelper{ /// <summary> /// Serializes the specified Class to XML. /// </summary> /// <param name="path">The path.</param> /// <param name="object">The @object.</param> /// <returns></returns> public static Boolean Serialize(String path, object @object) { try { if (File.Exists(path)) File.Delete(path); } catch { } FileStream fs = null; try { using (fs = new FileStream(path, FileMode.Create)) { using (var w = new StreamWriter(fs, Encoding.UTF8)) { var s = new XmlSerializer(@object.GetType()); s.Serialize(w, @object); } } return true; } catch (Exception ex) { try { if (fs != null) fs.Close(); } catch { } MessageBox.Show("XML Serialize: " + ex); } return false; } /// <summary> /// Deserializes the XML to Class. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path">The path.</param> /// <returns></returns> public static T Deserialize<T>(String path) { T result = default(T); FileStream fs = null; try { XmlSerializer s = new XmlSerializer(typeof(T)); fs = new FileStream(path, FileMode.Open, FileAccess.Read); result = (T)s.Deserialize(fs); fs.Close(); return result; } catch (Exception ex) { try { if (fs != null) fs.Close(); } catch { } MessageBox.Show("XML Deserialize: " + ex); return result; } }}\[/code\]I used the above code to generate this:\[code\]<?xml version="1.0" encoding="utf-8"?><Translator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Translation> <Phrases> <Phrase> <PhraseID>none</PhraseID> <PhraseString>None</PhraseString> </Phrase> <Phrase> <PhraseID>Button_Start</PhraseID> <PhraseString>Start</PhraseString> </Phrase> <Phrase> <PhraseID>Button_Stop</PhraseID> <PhraseString>Stop</PhraseString> </Phrase> </Phrases> </Translation></Translator>\[/code\]However when I try to Deserialize this xml file I get the error I posted above.Any ideas why this is happening?Thanks -Ryuk-