Expand|Select|Wrap|Line Numbers
- [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")]
- [System.SerializableAttribute()]
- [System.Diagnostics.DebuggerStepThroughAttribute()]
- [System.ComponentModel.DesignerCategoryAttribute("code")]
- [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
- public partial class PageFile
- {
- private string parentGuidField;
- private string nameField;
- public string ParentGuid
- {
- get
- {
- return this.parentGuidField;
- }
- set
- {
- this.parentGuidField = value;
- }
- }
- public XmlCDataSection Name
- {
- get
- {
- XmlDataDocument doc = new XmlDataDocument();
- XmlCDataSection cd = doc.CreateCDataSection(this.nameField);
- return cd;
- }
- set
- {
- this.nameField = value.Value;
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- public static T DeserializeObject<T>(string XML)
- {
- using (StringReader stringreader = new StringReader(XML))
- {
- XmlSerializer serializer = new XmlSerializer(typeof(T));
- return (T)serializer.Deserialize(stringreader);
- }
- }
DeserializeObject<PageFile>(myXmlString);
When I do this I get the following error:
"Unable to cast object of type 'System.Xml.XmlText' to type 'System.Xml.XmlCDataSection'."
If "Name" was a string everything works fine. The problem is I have to have "Name" as a XmlCDataSection, how do I Deserialize my PageFile class using the DeserializeObject method that I use else where in my project?
Many thanks