0

I am trying to read an xml with an XmlReader, but I receive an exception on something that I didn't expect.

ArgumentException: Specified type 'System.Guid' is not supported.
System.Xml.XmlReader.ValueAs (System.String text, System.Type type, IXmlNamespaceResolver resolver)
System.Xml.XmlReader.ReadElementContentAs (System.Type type, IXmlNamespaceResolver resolver)

The exception was thrown in the following line of code:

propInfo.Value = _cReader.ReadElementContentAs(propInfo.PropertyType, null);

Where propInfo is a wrapper for a public property (getter-setter) that has to be serialized. In this line of code I try to read the value from xml and set it in the wrapper. I thought that a System.Guid would be supported, because there is also a XmlConvert.ToGuid() method.

What is a good way to serialize an xmlelement of a single type via this way? I cannot use XmlSerializer for complex reasons with Mono.

Marnix
  • 6,384
  • 4
  • 43
  • 78
  • So... read/write as a string and use XmlConvert to shim between Guid / string...? – Marc Gravell Mar 08 '13 at 09:35
  • There are more types than only a Guid actually and I was hoping for a more general answer that I can use on other types as well. Even those that are not in `XmlConvert`. – Marnix Mar 08 '13 at 09:36

0 Answers0