I have a verb I need to read in spanish. However, the Twilio .Net parser is failing with Invalid character in the given encoding. The line that's failing (edited for brevity) is:
> <Say voice="man" language="es">cita para la instalación de alfombra,
> el lunes, 15 de enero</Say>
My XML is defined as <?xml version="1.0" encoding="utf-8"?>
How can I make the Twilio .Net library parse that character correctly? If I put this directly in a TWIML bin it works, however, the .Net SDK doesn't parse it.
Updated: Adding code examples
I'm using the helper library to generate VoiceResponse objects and returning them through the webhook. For example:
foreach (var (translation, date) in installations)
{
gather.Append(new Say($"{translation} {SpanishDate(date)}", Say.VoiceEnum.Man, language: "es"));
}
public static string SpanishDate(DateTime date)
{
return $"el {date.ToString("dddd", new CultureInfo("es-ES"))}, {(date.Day == 1 ? "primo" : date.Day.ToString())} de {date.ToString("MMMM", new CultureInfo("es-ES"))}";
}
I'm looking at the resulting XML that gets returned by the helper library, which is:
<Say voice="man" language="es">Cita para la instalacion de pisos de madera el miércoles, 28 de febrero</Say>
The XML that's generated by the VoiceResponse object (using the ToString() method) is stored in blob storage until the call is placed, then returned as a TwiMLResult in the webhook.
The exception is being thrown in the helper library's TwiMLResult constructor, which is attempting to parse the XML and is failing.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32& bytesCount, Int32& charsCount)
at System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount)
at System.Xml.XmlTextReaderImpl.ReadData()
at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
at System.Xml.XmlTextReaderImpl.FinishPartialValue()
at System.Xml.XmlTextReaderImpl.get_Value()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at Twilio.AspNet.Mvc.TwiMLResult.LoadFromString(String twiml, Encoding encoding)
at Twilio.AspNet.Mvc.TwiMLResult..ctor(String twiml)