NullReferenceException in DataPager control - by Richard Deeming

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


4
0
Sign in
to vote
ID 357344 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 7/22/2008 1:06:17 PM
Access Restriction Public

Description

A DataPager control with the QueryStringField property set throws a NullReferenceException when the query-string contains either an empty element (eg: "?&foo=bar") or an element with no value (eg: "?foo").

The exception is thrown from the internal GetQueryStringNavigateUrl method of the DataPager class. In some circumstances, the key returned from the QueryString.AllKeys collection is null, but the method fails to check for a null value.
Sign in to post a comment.
Posted by Microsoft on 7/22/2008 at 10:25 PM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by Richard Deeming on 7/22/2008 at 1:24 PM
The problem is in the GetQueryStringNavigateUrl method:

foreach (string key in request.QueryString.AllKeys)
{
    if (... && !key.Equals(queryStringField, StringComparison.OrdinalIgnoreCase))

When the query-string collection contains a null key, this will throw a NullReferenceException. The code should read:

if (... && !string.Equals(key, queryStringField, ...))

Since the Equals method includes checks for null values, the problem would be solved.
Posted by Richard Deeming on 7/22/2008 at 1:20 PM
I have uploaded a demonstration. Extract the files to a new folder, and create an application in IIS (or run Casini on the folder). The two links at the top of the page - "Error 1" and "Error 2" - will demonstrate the problem.