469,306 Members | 1,903 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Unable to translate Unicode character \u00E9 at index 5409 to specified code page.

I've got some C# 2.0 code that has been working for a year.

using (XmlWriter w = XmlWriter.Create("out.xml" ,settings)) {
// many lines of code to write to w
w.WriteStartElement("contactTypeRef");

Suddently, I'm getting this 100% repeatable error:

************** Exception Text **************
System.Text.EncoderFallbackException: Unable to translate Unicode character
\u00E9 at index 5409 to specified code page.
at System.Text.EncoderExceptionFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Xml.CharEntityEncoderFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Text.EncoderFallbackBuffer.InternalFallback (Char ch, Char*& chars)
at System.Text.ASCIIEncoding.GetBytes(Char* chars, Int32 charCount, Byte*
bytes, Int32 byteCount, EncoderNLS encoder)
at System.Text.EncoderNLS.Convert(Char* chars, Int32 charCount, Byte* bytes,
Int32 byteCount, Boolean flush, Int32& charsUsed, Int32& bytesUsed, Boolean&
completed)
at System.Text.EncoderNLS.Convert(Char[] chars, Int32 charIndex, Int32
charCount, Byte[] bytes, Int32 byteIndex, Int32 byteCount, Boolean flush, Int32&
charsUsed, Int32& bytesUsed, Boolean& completed)
at System.Xml.XmlEncodedRawTextWriter.EncodeChars(Int 32 startOffset, Int32
endOffset, Boolean writeAllToStream)
at System.Xml.XmlEncodedRawTextWriter.FlushBuffer()
at System.Xml.XmlEncodedRawTextWriter.RawText(Char* pSrcBegin, Char* pSrcEnd)
at System.Xml.XmlEncodedRawTextWriter.RawText(String s)
at System.Xml.XmlEncodedRawTextWriter.WriteStartEleme nt(String prefix, String
localName, String ns)
at System.Xml.XmlWellFormedWriter.WriteStartElement(S tring prefix, String
localName, String ns)
at System.Xml.XmlWriter.WriteStartElement(String localName)

I thought the whole point of using an XmlWriter was that it would translate the
chars into legal XML.

How can I resolve this?
--
Thanks in advance, Les Caudle
Jun 20 '07 #1
5 14456
Les Caudle wrote:
I've got some C# 2.0 code that has been working for a year.

using (XmlWriter w = XmlWriter.Create("out.xml" ,settings)) {
// many lines of code to write to w
w.WriteStartElement("contactTypeRef");

Suddently, I'm getting this 100% repeatable error:

************** Exception Text **************
System.Text.EncoderFallbackException: Unable to translate Unicode character
\u00E9 at index 5409 to specified code page.
at System.Text.EncoderExceptionFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Xml.CharEntityEncoderFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Text.EncoderFallbackBuffer.InternalFallback (Char ch, Char*& chars)
at System.Text.ASCIIEncoding.GetBytes(Char* chars, Int32 charCount, Byte*
bytes, Int32 byteCount, EncoderNLS encoder)
at System.Text.EncoderNLS.Convert(Char* chars, Int32 charCount, Byte* bytes,
Int32 byteCount, Boolean flush, Int32& charsUsed, Int32& bytesUsed, Boolean&
completed)
at System.Text.EncoderNLS.Convert(Char[] chars, Int32 charIndex, Int32
charCount, Byte[] bytes, Int32 byteIndex, Int32 byteCount, Boolean flush, Int32&
charsUsed, Int32& bytesUsed, Boolean& completed)
at System.Xml.XmlEncodedRawTextWriter.EncodeChars(Int 32 startOffset, Int32
endOffset, Boolean writeAllToStream)
at System.Xml.XmlEncodedRawTextWriter.FlushBuffer()
at System.Xml.XmlEncodedRawTextWriter.RawText(Char* pSrcBegin, Char* pSrcEnd)
at System.Xml.XmlEncodedRawTextWriter.RawText(String s)
at System.Xml.XmlEncodedRawTextWriter.WriteStartEleme nt(String prefix, String
localName, String ns)
at System.Xml.XmlWellFormedWriter.WriteStartElement(S tring prefix, String
localName, String ns)
at System.Xml.XmlWriter.WriteStartElement(String localName)

I thought the whole point of using an XmlWriter was that it would translate the
chars into legal XML.
Are you perhaps trying to write out XML in an encoding like US-ASCII
that does not include the character 'é'?
What are you XmlWriterSettings exactly when you get that error?
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 20 '07 #2
On Wed, 20 Jun 2007 17:05:24 +0200, Martin Honnen <ma*******@yahoo.dewrote:
>Les Caudle wrote:
>I've got some C# 2.0 code that has been working for a year.

using (XmlWriter w = XmlWriter.Create("out.xml" ,settings)) {
// many lines of code to write to w
w.WriteStartElement("contactTypeRef");

Suddently, I'm getting this 100% repeatable error:

************** Exception Text **************
System.Text.EncoderFallbackException: Unable to translate Unicode character
\u00E9 at index 5409 to specified code page.
at System.Text.EncoderExceptionFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Xml.CharEntityEncoderFallbackBuffer.Fallbac k(Char charUnknown,
Int32 index)
at System.Text.EncoderFallbackBuffer.InternalFallback (Char ch, Char*& chars)
at System.Text.ASCIIEncoding.GetBytes(Char* chars, Int32 charCount, Byte*
bytes, Int32 byteCount, EncoderNLS encoder)
at System.Text.EncoderNLS.Convert(Char* chars, Int32 charCount, Byte* bytes,
Int32 byteCount, Boolean flush, Int32& charsUsed, Int32& bytesUsed, Boolean&
completed)
at System.Text.EncoderNLS.Convert(Char[] chars, Int32 charIndex, Int32
charCount, Byte[] bytes, Int32 byteIndex, Int32 byteCount, Boolean flush, Int32&
charsUsed, Int32& bytesUsed, Boolean& completed)
at System.Xml.XmlEncodedRawTextWriter.EncodeChars(Int 32 startOffset, Int32
endOffset, Boolean writeAllToStream)
at System.Xml.XmlEncodedRawTextWriter.FlushBuffer()
at System.Xml.XmlEncodedRawTextWriter.RawText(Char* pSrcBegin, Char* pSrcEnd)
at System.Xml.XmlEncodedRawTextWriter.RawText(String s)
at System.Xml.XmlEncodedRawTextWriter.WriteStartEleme nt(String prefix, String
localName, String ns)
at System.Xml.XmlWellFormedWriter.WriteStartElement(S tring prefix, String
localName, String ns)
at System.Xml.XmlWriter.WriteStartElement(String localName)

I thought the whole point of using an XmlWriter was that it would translate the
chars into legal XML.

Are you perhaps trying to write out XML in an encoding like US-ASCII
that does not include the character 'é'?
What are you XmlWriterSettings exactly when you get that error?

Martin - Yes, I'm using Encoding.ASCII.

If I output to UTF8 encoding, all is fine, but NetSuite will no longer import
the XML. So, I need to find a way to automate creating the XML formatted as
ASCII.

Here are the settings:

settings.NewLineChars = @"\r\n";
settings.NewLineHandling = NewLineHandling.Replace;
settings.NewLineOnAttributes = true;
settings.Encoding = Encoding.ASCII;

Thanks, Les Caudle
Jun 20 '07 #3
Les Caudle wrote:
Martin - Yes, I'm using Encoding.ASCII.

If I output to UTF8 encoding, all is fine, but NetSuite will no longer import
the XML. So, I need to find a way to automate creating the XML formatted as
ASCII.

Here are the settings:

settings.NewLineChars = @"\r\n";
settings.NewLineHandling = NewLineHandling.Replace;
settings.NewLineOnAttributes = true;
settings.Encoding = Encoding.ASCII;
Any XML parser/application is supposed to support UTF-8 and UTF-16 but
not ASCII.
I don't think XmlWriter can do what you want unless your code manually
makes sure it writes out non-ASCII characters as character references
e.g. like this

xmlWriter.WriteStartElement("foo");
foreach (char c in "Je suis fatigué.") {
if (c < 128) {
xmlWriter.WriteString(c.ToString());
}
else {
xmlWriter.WriteCharEntity(c);
}
}
xmlWriter.WriteEndElement();

that then results in

<foo>Je suis fatigu&#xE9;.</foo>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 21 '07 #4
Martin Honnen wrote:
Any XML parser/application is supposed to support UTF-8 and UTF-16 but
not ASCII.
I don't think XmlWriter can do what you want unless your code manually
makes sure it writes out non-ASCII characters as character references
Another solution could be to generate the XML in UTF-8 or UTF-16 first,
then to apply an XSLT styleshet like this

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no" encoding="US-ASCII"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

with .NET XslCompiledTransform. That way .NET seems to be able to ensure
the output is US-ASCII by using character references as needed for
characters that are outside of the target encoding.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Jun 21 '07 #5
Hello Les Caudle,

I totally agree with Martin.

ASCIIEncoding object cannot encode a character whose Unicode code point
value is outside the range U+0000 to U+007F.
According to the error message you pasted, WriteStartElement() method want
to write an illegal character (\u00E9 ¨¦) into ASCII encoded XML file. Thus
.net runtime throw an EncoderFallbackException.

Have you tried Martin's suggestion so far? Does this method works for you?
If you face any further issue, please update here. Thus we could follow up.
:)

Have a great day,
Sincerely,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by nicolas.riesch | last post: by
27 posts views Thread by EU citizen | last post: by
11 posts views Thread by Patrick Van Esch | last post: by
24 posts views Thread by chri_schiller | last post: by
1 post views Thread by anonymous | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.