Bug 2397 - Wrong DataItem type in Repeater ItemDataBound event when the data source is a SortedDictionary
Summary: Wrong DataItem type in Repeater ItemDataBound event when the data source is a...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Web (show other bugs)
Version: 2.10.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-12-07 13:19 UTC by Cédric Belin
Modified: 2012-04-28 13:53 UTC (History)
2 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:


Description Cédric Belin 2011-12-07 13:19:43 UTC
I have an ASP.NET site. One page uses a Repeater control.
This control is bound to a SortedDictionary<string, string> collection (returned as a IDictionary<string, string> via the SelectMethod property of a ObjectDataSource control).

I customize the display of the Repeater items in the ItemDataBound event.
Normally, the DataItem property of the RepeaterItemEventArgs should be filled with a KeyValuePair<string, string> instance. Instead, I get a DictionaryEntry instance.

On Windows 7 / IIS 7.5 / .NET Framework 4.0, I get the expected KeyValuePair<string, string> object.
On Mono, if I replace the SortedDictionary<string, string> data source by a Dictionary<string, string>, I get the expected KeyValuePair too.

It seems that there is a bug in SortedDictionary or ObjectDataSource implementation.

My specs : Mac OS X 10.7.2, Mono 2.10.6 (running on Apache and mod_mono) with ASP.NET 4.0 profile.
The bug is reproducible on a Linux Ubuntu 11.04 system with the same settings (Mono version is 2.10.5).

Code extract of the ASPX page :

<asp:ObjectDataSource id="SiteDataSource" TypeName="HomePage.Default" SelectMethod="GetSites" runat="server" />
<asp:Repeater DataSourceID="SiteDataSource" OnItemDataBound="OnSiteDataBound" runat="server">
			<asp:HyperLink NavigateUrl='<%# Eval("Value") %>' Text='<%# Eval("Key") %>' runat="server" />
			<asp:HyperLink id="AdminLink" ImageUrl="~/Images/Admin.png" ToolTip="Module d'administration" Visible="false" runat="server" />

Code extract of the code behind class (the OnSiteDataBound method takes the bug into account) :

public static IDictionary<string, string> GetSites()
	var list=new SortedDictionary<string, string>();
	var hiddenDirectories=new List<string>

	foreach(var path in Directory.GetDirectories(WebConfigurationManager.AppSettings["Server.Root"]).Select(x=>Path.GetFileName(x)))
		if(!hiddenDirectories.Contains(path)) list.Add(path, string.Format(CultureInfo.InvariantCulture, "http://dev.{0}/{1}", Global.Host, path));
	return list;

protected void OnSiteDataBound(object sender, RepeaterItemEventArgs e)
	if(e.Item.ItemType!=ListItemType.AlternatingItem && e.Item.ItemType!=ListItemType.Item) return;
	string folder, url;
		var monoDataItem=(DictionaryEntry) e.Item.DataItem;
		var dotnetDataItem=(KeyValuePair<string, string>) e.Item.DataItem;
	if(Directory.Exists(Path.Combine(WebConfigurationManager.AppSettings["Server.Root"], folder, "Admin")))
		var link=(HyperLink) e.Item.FindControl("AdminLink");
Comment 1 Dimitar Dobrev 2012-04-28 13:53:33 UTC
I second that, with a small clarification: it has nothing to do with Repeater or with ASP.NET for that matter, it is a bug in SortedDictionary. The problem is in SortedDictionary.Enumerator.IEnumerator.Current - it returns CurrentNode.AsDE () and it should return CurrentNode.AsKV (see https://raw.github.com/mono/mono/master/mcs/class/System/System.Collections.Generic/SortedDictionary.cs).

Note You need to log in before you can comment on or make changes to this bug.