Bug 2455 - HashSet<object> throws ArgumentException when inserting BindingFlag and Tuple<,>
Summary: HashSet<object> throws ArgumentException when inserting BindingFlag and Tuple<,>
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2011-12-11 03:01 UTC by knittl89+bugs
Modified: 2011-12-11 16:26 UTC (History)
3 users (show)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description knittl89+bugs 2011-12-11 03:01:02 UTC
When trying to add System.Reflection.BindingFlags.NonPublic and Tuple<int, int>(1,1) to an instance of HashSet<object>, it throws an System.ArgumentException.

The exception happens when comparing the BindingFlag to the Tuple. I'm not sure if the two objects should actually ever be compared? When using a HashSet<object> I expect objects to be compared as their common base class (in this case "object"), but it appears they are compared as their actual types .Equals is dynamically bound.

Here's a really simple test case [with syntax highlighting](http://paste2.org/p/1818470) to produce the exception:

using System;
using System.Collections.Generic;

namespace TupleTest {
	public class TupleTest {
		public static void Main (String[] args) {
			var objects = new HashSet<object>();
			
			// the following combination of objects crashes,
			// other values do not produce the crash
			Tuple<int, int> tuple = new Tuple<int, int>(1, 1);
			System.Reflection.BindingFlags flag = System.Reflection.BindingFlags.NonPublic;
			
			// flag and tuple have to be added in this order
			objects.Add(flag);
			// throws System.ArgumentException at System.Tuple`2[System.Int32,System.Int32].System.Collections.IStructuralEquatable.Equals (System.Object other, IEqualityComparer comparer) [0x00015] in /.../mcs/class/corlib/System/Tuples.cs:176 
			/**
				* Unhandled Exception: System.ArgumentException: Value does not fall within the expected range.
				* at System.Tuple`2[System.Int32,System.Int32].System.Collections.IStructuralEquatable.Equals (System.Object other, IEqualityComparer comparer) [0x00015] in /.../mono/mcs/class/corlib/System/Tuples.cs:176 
				* at System.Tuple`2[System.Int32,System.Int32].Equals (System.Object obj) [0x00000] in /.../mcs/class/corlib/System/Tuples.cs:168 
				* at System.Collections.Generic.EqualityComparer`1+DefaultComparer[System.Object].Equals (System.Object x, System.Object y) [0x00000] in <filename unknown>:0 
				* at System.Collections.Generic.HashSet`1[System.Object].SlotsContainsAt (Int32 index, Int32 hash, System.Object item) [0x00022] in /.../mcs/class/System.Core/System.Collections.Generic/HashSet.cs:166 
				* at System.Collections.Generic.HashSet`1[System.Object].Add (System.Object item) [0x00019] in /.../mcs/class/System.Core/System.Collections.Generic/HashSet.cs:249  
				* at TupleTest.TupleTest.Main (System.String[] args) [0x00000] in /home/knittl/.../Tuple.cs:26 
				*/
			objects.Add(tuple);
		}
	}
}
Comment 1 Rodrigo Kumpera 2011-12-11 16:15:07 UTC
working on it
Comment 2 Rodrigo Kumpera 2011-12-11 16:26:12 UTC
Fixed on trunk.