Microsoft KB Archive/317610

= BUG: XmlTextReader Decodes URLs Before Downloading Resources Resulting in Unpredictable Behavior =

Article ID: 317610

Article Last Modified on 2/22/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.0
 * Microsoft .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 &quot;More Information&quot; 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.



Steps to Reproduce the Behavior
 Start Microsoft Visual Studio .NET. Create a new ASP.NET Web Service application in Microsoft Visual C# .NET. In Solution Explorer, right-click the project, and then click Add Web Form.  Add the following using statement to the &quot;General Declarations&quot; 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;   Paste the following code in the Page_Load event: NameValueCollection x = Request.QueryString; String[] arr1 = x.AllKeys; Response.Write(&quot; &quot;); string msg = String.Format(&quot;WebService received {0} parameters&quot;, x.Count); Response.Write(msg); Response.Write(&quot; &quot;); Response.End; </li> Save the project.</li> Right-click the solution in Solution Explorer, and then click New Project. Add an ASP.NET Web Application.</li> Add two Button Web server controls to the Web Form.</li> Change the Text property for Button1 to Test, and then change the Text property for Button2 to Stream .</li>  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; </li>  Paste the following code in the Button1_Click event: string q1 = &quot;a&b=6&quot;; string uri = &quot;http://localhost/WebService1/WebForm1.aspx?q1=&quot; + HttpUtility.UrlEncode(q1); XmlTextReader r = new XmlTextReader(uri); r.MoveToContent; Response.Write(r.ReadOuterXml); r.Close; </li>  Paste the following code in the Button2_Click event: string q1 = &quot;a&b=6&quot;; string uri = &quot;http://localhost/WebService1/WebForm1.aspx?q1=&quot; + 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. </li> Make sure that the startup project and the page are set.</li> Save and then run the project.</li> Click Test. Notice that the text &quot;WebService received 2 parameters&quot; appears.</li> Click Stream. Notice that the text &quot;WebService received 1 parameters&quot; appears.</li></ol>

Keywords: kbbug kbnofix KB317610

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.