Edit

Share via


Manage invalid characters

There is a set of characters that can't be saved in string or memo columns. When an application saves data containing these characters to Dataverse, the following error occurs:

Name: InvalidCharactersInField
Hexadecimal error code: 80040278
Error Number: -2147220872
Description: The field '{0}' contains one or more invalid characters.

Dataverse uses the System.Xml.XmlConvert.VerifyXmlChars(String) Method for every string value passed to these columns. This error is thrown on the first invalid character encountered.

You might encounter these characters in email content that includes replies or when text is copied from another source that might have characters to control presentation.

To prevent this error, you can:

  • HTML encode the content before saving.

  • Remove the individual invalid characters, use the System.Xml.XmlConvert.IsXmlChar(Char) Method as shown in the following example:

    static string RemoveInvalidXmlChars(string text) {
        var validXmlChars = text.Where(ch => XmlConvert.IsXmlChar(ch)).ToArray();
        return new string(validXmlChars);
    }
    

See Also

Work with data using code in Dataverse (Power Apps)