none
Read unicode fail .net 4.5 XmlReader.Create in .net 3.5 not exeption RRS feed

  • Question

  • this my source

     var fileName = @"namefile";
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ProhibitDtd = false;
                settings.XmlResolver = null;
                settings.IgnoreWhitespace = true;
                try
                {
                    XmlReader reader = XmlReader.Create(fileName, settings);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Message:{0}", ex.Message);
                    Console.ReadLine();
                }


    this my file name 

    fileName "have charecter  " string

    this exception 

    ex.Message "Could not find a part of the path '%EE%82%AC'." string




    • Edited by Hung Kieu Friday, December 27, 2019 10:06 AM change theard
    Wednesday, December 18, 2019 4:02 AM

Answers

  • Try this:

     

       var ub = new UriBuilder { Scheme = "file", Path = fileName, Host = null };

       XmlReader reader = XmlReader.Create( ub.Uri.AbsoluteUri, settings );

     

     

    Or consider XmlReader.Create that deals with streams and readers.


    • Edited by Viorel_MVP Wednesday, December 18, 2019 6:14 AM
    • Marked as answer by Hung Kieu Wednesday, December 18, 2019 6:41 AM
    Wednesday, December 18, 2019 6:10 AM

All replies

  • Try this:

     

       var ub = new UriBuilder { Scheme = "file", Path = fileName, Host = null };

       XmlReader reader = XmlReader.Create( ub.Uri.AbsoluteUri, settings );

     

     

    Or consider XmlReader.Create that deals with streams and readers.


    • Edited by Viorel_MVP Wednesday, December 18, 2019 6:14 AM
    • Marked as answer by Hung Kieu Wednesday, December 18, 2019 6:41 AM
    Wednesday, December 18, 2019 6:10 AM
  • Thanks you!

    it worked!

    please help me 

    Why is this different, are there any references to it?

    Wednesday, December 18, 2019 6:36 AM
  • XmlReader.Create accepts a Uri (not a filename), such as “http://.../myfile.xml” or “file:///C:\myfile.xml”. You can also try ‘XmlReader.Create(“file:///” + fileName)’. Probably the new version is more restrictive. Using UriBuilder seems to guarantee the correct representation of Uri.

     

    Wednesday, December 18, 2019 6:55 AM
  • I believe you'll want to file a bug that, when a file path with "file://" or no protocol specified is passed in XmlReader.Create(), it should not use XmlResolver to treat it as Uri, in order to prevent non-"lower ASCII" range character being escaped in URL format.

    ======

    Sidetalk: I wonder if those Korean users have hit by this problem long before (the earliest problem I can find on the web regarding escapes in XmlReader.Create() dates back on early 2017, and they recommands pipe it with StreamReader()).

    Provided that they use ₩(U+20A9) as path seperator, which is very likely to be "escaped" in Uri.


    Wednesday, December 18, 2019 9:21 AM
    Answerer
  • I believe you'll want to file a bug that, when a file path with "file://" or no protocol specified is passed in XmlReader.Create(), it should not use XmlResolver to treat it as Uri, in order to prevent non-"lower ASCII" range character being escaped in URL format.

    ======

    Sidetalk: I wonder if those Korean users have hit by this problem long before (the earliest problem I can find on the web regarding escapes in XmlReader.Create() dates back on early 2017, and they recommands pipe it with StreamReader()).

    Provided that they use ₩(U+20A9) as path seperator, which is very likely to be "escaped" in Uri.


    Thanks you for your supported!

    i think i will use 

    var ub = new UriBuilder { Scheme = "file", Path = fileName, Host = null };

       XmlReader reader = XmlReader.Create( ub.Uri.AbsoluteUri, settings );

    Wednesday, December 18, 2019 10:32 AM