Re: aps.net : BIG BUG in streamwriter
- From: Steph <steph@xxxxxxxxxxxx>
- Date: Thu, 02 Apr 2009 09:38:12 +0200
Pavel Minaev wrote:
On Apr 1, 11:21 pm, Steph <st...@xxxxxxxxxxxx> wrote:ok ok, for you : here a simple code in a new empty website :
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.IO.StreamWriter sw = new
System.IO.StreamWriter(Server.MapPath("./") + "test.xml", false,
System.Text.Encoding.UTF8);
sw.Write("a text");
sw.Close();
}
}
that write a UTF-16 File !!!! not a a UTF-8 !!!!!! take a time to just
look the BOM ! (edit file in a hexa editor)
With those precise steps to reproduce, it wrote an UTF-8 file for me,
with UTF-8 BOM (EF BB BF). No bug. This is on VS2008 SP1 (and I was
using its built-in web server to test, not IIS).
Maybe, after the file is written to disk, you're opening it in some
editor which proceeds to rewrite it as UTF-16? I really don't see any
explanation... it could be that you're using an older .NET version,
but even then I can't imagine how such a bug could work.
Oh, actually, I have another suspicion. After that file is written,
how do you open it? Directly from the disk in your website folder? Or,
perchance, using the browser (i.e. going to /WebSite1/test.xml)? If
the latter, then it could be the HTTP server that transcodes it.
hello,
i use IIs with Net2.5x.
"you're opening it in some editor which proceeds to rewrite it as UTF-16?"
no, because, .NET it self cannot open it if you specify the encoding in deserialization.
And i open the xml file directly from the disk : "right click + open with"...
and i confirm : it's a utf-16 file (bom : fffe) with chars in utf-8...
if i don't open the xml file manually for change the bom :
when i want deserialize it with an utf-8 encoding... bug. "unrecognized chars at position 1,1"
after i open manually the file in an hexa decimal editor, the bom is UTF-16, i save in utf-8 and i can deserialize it (because, the bom is utf-8 and chars encoding is also utf-8)
"(and I was using its built-in web server to test, not IIS)."
i have try : identically
i will install .NET3 .... may be !
it s a bug in 2.5 !
.
- Follow-Ups:
- Re: aps.net : BIG BUG in streamwriter
- From: jmostert
- Re: aps.net : BIG BUG in streamwriter
- References:
- aps.net : BIG BUG in streamwriter
- From: Steph
- Re: aps.net : BIG BUG in streamwriter
- From: Jeroen Mostert
- Re: aps.net : BIG BUG in streamwriter
- From: Steph
- Re: aps.net : BIG BUG in streamwriter
- From: Pavel Minaev
- aps.net : BIG BUG in streamwriter
- Prev by Date: Re: aps.net : BIG BUG in streamwriter
- Next by Date: Re: aps.net : BIG BUG in streamwriter
- Previous by thread: Re: aps.net : BIG BUG in streamwriter
- Next by thread: Re: aps.net : BIG BUG in streamwriter
- Index(es):