BUG: XmlTextReader Decodes URLs Before Downloading Resources Resulting in Unpredictable Behavior (317610)



The information in this article applies to:

  • Microsoft XML Classes (included with the .NET Framework 1.0)
  • Microsoft XML Classes (included with the .NET Framework 1.1)

This article was previously published under Q317610
This article refers to the following Microsoft .NET Framework Class Library namespace:
  • System.Collections.Specialized

SYMPTOMS

When you use the XmlTextReader object to download resource files, the reader decodes the URL for the resources. If the URL contains any special characters (for example, ampersands or percent signs), this may result in unpredictable behavior.

RESOLUTION

To resolve the problem, follow these steps:
  1. Use the XmlUrlResolver and the System.IO.Stream classes to map the specified URL.
  2. Create an XmlTextReader object and pass the Stream as the parameter.
For an example, see the "More Information" section of this article.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Start Microsoft Visual Studio .NET.
  2. Create a new ASP.NET Web Service application in Microsoft Visual C# .NET.
  3. In Solution Explorer, right-click the project, and then click Add Web Form.
  4. Add the following using statement to the "General Declarations" section of WebForm1 so that you do not need to qualify declarations in the System.Collections.Specialized namespaces later in your code:
    using System.Collections.Specialized;
    					
  5. Paste the following code in the Page_Load event:
       NameValueCollection x = Request.QueryString;
       String[] arr1 = x.AllKeys; 
       Response.Write("<root>");
       string msg = String.Format("WebService received {0} parameters", x.Count);
       Response.Write(msg);
       Response.Write("</root>");
       Response.End();
    					
  6. Save the project.
  7. Right-click the solution in Solution Explorer, and then click New Project. Add an ASP.NET Web Application.
  8. Add two Button Web server controls to the Web Form.
  9. Change the Text property for Button1 to Test, and then change the Text property for Button2 to Stream.
  10. Add the following namespaces so that you are not required to qualify declarations in those namespaces later in your code.
      using System.Xml;
      using System.IO;
    					
  11. Paste the following code in the Button1_Click event:
      string q1 = "a&b=6";
      string uri = "http://localhost/WebService1/WebForm1.aspx?q1=" + HttpUtility.UrlEncode(q1);
      XmlTextReader r = new XmlTextReader(uri);
      r.MoveToContent();
      Response.Write(r.ReadOuterXml());
      r.Close();
    					
  12. Paste the following code in the Button2_Click event:
      string q1 = "a&b=6";
      string uri = "http://localhost/WebService1/WebForm1.aspx?q1=" + HttpUtility.UrlEncode(q1);
    
      XmlUrlResolver resolver = new XmlUrlResolver();
      Stream stream = (Stream)resolver.GetEntity(new Uri(uri), null, null);
      XmlTextReader r = new XmlTextReader(stream);
      r.MoveToContent();
      Response.Write(r.ReadOuterXml());
      r.Close();
    						
    Make sure that the URL is correct as entered in the Click event for each button.
  13. Make sure that the startup project and the page are set.
  14. Save and then run the project.
  15. Click Test. Notice that the text "WebService received 2 parameters" appears.
  16. Click Stream. Notice that the text "WebService received 1 parameters" appears.

Modification Type:MinorLast Reviewed:12/12/2003
Keywords:kbbug kbnofix KB317610