[Mono-bugs] [Bug 661462] New: Queryable.AsQueryable(IEnumerable) breaks on Dictionary<T, V>.ValueCollection if T!=V

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Dec 27 04:29:07 EST 2010


https://bugzilla.novell.com/show_bug.cgi?id=661462

https://bugzilla.novell.com/show_bug.cgi?id=661462#c0


           Summary: Queryable.AsQueryable(IEnumerable) breaks on
                    Dictionary<T,V>.ValueCollection if T!=V
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.8.x
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: david at dasz.at
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)
AppleWebKit/534.10 (KHTML, like Gecko) Chrome/8.0.552.224 Safari/534.10

mcs/class/System.Core/System.Linq/Queryable.cs:166 uses
GetFirstGenericArgument() on the source enumeration type to create the
resulting QueryableEnumerable<>, since the Dictionary<T,V>.ValueCollection is
an IEnumerable<V>, this fails.

Reproducible: Always

Steps to Reproduce:
Compile and run this program:


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public class Test {

public static void Main(string[]args) {
        var t = new Dictionary<int, string>();
        t[100] = "foo";
        IEnumerable broken = (IEnumerable)t.Values;
        foreach(string x in broken.AsQueryable()) {
                Console.WriteLine("element: {0}", x);
        }
}

}

Actual Results:  
Unhandled Exception: System.MissingMethodException: No constructor found for
System.Linq.QueryableEnumerable`1[[System.Int32, mscorlib, Version=2.0.0.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089]]::.ctor(System.Collections.Generic.Dictionary`2+ValueCollection[System.Int32,System.String])
  at System.Activator.CreateInstance (System.Type type, BindingFlags
bindingAttr, System.Reflection.Binder binder, System.Object[] args,
System.Globalization.CultureInfo culture, System.Object[] activationAttributes)
[0x00180] in
/srv/CCNet/mono/src/mono.git/mcs/class/corlib/System/Activator.cs:300
  at System.Activator.CreateInstance (System.Type type, System.Object[] args,
System.Object[] activationAttributes) [0x00000] in
/srv/CCNet/mono/src/mono.git/mcs/class/corlib/System/Activator.cs:234
  at System.Activator.CreateInstance (System.Type type, System.Object[] args)
[0x00000] in
/srv/CCNet/mono/src/mono.git/mcs/class/corlib/System/Activator.cs:229
  at System.Linq.Queryable.AsQueryable (IEnumerable source) [0x00047] in
/srv/CCNet/mono/src/mono.git/mcs/class/System.Core/System.Linq/Queryable.cs:166
  at Test.Main (System.String[] args) [0x00000] in <filename unknown>:0


Expected Results:  
The program should produce the output 

"element: foo\n"

This also happens on 2.6.7.0.

This can be worked around by using the generic form of AsQueryable, i.e. not
casting to IEnumerable in the example).

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list