Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should really post the code of the class you're trying to serialize and deserialize. In the meantime, I'll make a guess.</p> <p>Most likely, the invalid character is in a field or property of type <code>string</code>. You will need to serialize that as an array of bytes, assuming you can't avoid having that character present at all:</p> <pre><code>[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); } } } </code></pre> <p>This produces XML like the following:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt; &lt;Base64Content&gt;AAECAwQFFA==&lt;/Base64Content&gt; &lt;/root&gt; </code></pre> <hr> <p>I see you'd probably prefer VB.NET:</p> <pre><code>''# Prettify doesn't like attributes as the first item in a VB code block, so this comment is here so that it looks right on StackOverflow. &lt;XmlRoot("root")&gt; _ Public Class HasBase64Content Private _content As String &lt;XmlIgnore()&gt; _ Public Property Content() As String Get Return _content End Get Set(ByVal value As String) _content = value End Set End Property &lt;XmlElement()&gt; _ Public Property Base64Content() As Byte() Get Return System.Text.Encoding.UTF8.GetBytes(Content) End Get Set(ByVal value As Byte()) If Value Is Nothing Then Content = Nothing Return End If Content = System.Text.Encoding.UTF8.GetString(Value) End Set End Property End Class </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload