You really have to publish the class code that you are trying to serialize and deserialize. In the meantime, I will make an assumption.
Most likely, an invalid character is in a field or property of type string . You will need to serialize this as an array of bytes, assuming that you cannot escape the presence of this character at all:
[XmlRoot("root")] public class HasBase64Content { internal HasBase64Content() { } [XmlIgnore] public string Content { get; set; } [XmlElement] public byte[] Base64Content { get { return System.Text.Encoding.UTF8.GetBytes(Content); } set { if (value == null) { Content = null; return; } Content = System.Text.Encoding.UTF8.GetString(value); } } }
This causes the XML to look like this:
<?xml version="1.0" encoding="utf-8"?> <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Base64Content>AAECAwQFFA==</Base64Content> </root>
I see that you will probably prefer VB.NET:
''
source share