[Mono-bugs] [Bug 691661] New: Cannot cast from dynamic to generic in Mono C# 4.0

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed May 4 08:03:37 EDT 2011



           Summary: Cannot cast from dynamic to generic in Mono C# 4.0
    Classification: Mono
           Product: Mono: Compilers
           Version: 2.10.x
          Platform: Macintosh
        OS/Version: Mac OS X 10.6
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: C#
        AssignedTo: msafar at novell.com
        ReportedBy: mark at markrendle.net
         QAContact: mono-bugs at lists.ximian.com
          Found By: Community User
           Blocker: No

Description of Problem:

In MS C# 4, this method compiles fine:

public IEnumerable<T> OfType<T>()
    // Source is an IEnumerable<dynamic>
    foreach (var item in _sourceEnumerator.Current)
        bool success = true;
        T cast;
            cast = (T)item;
        catch (RuntimeBinderException)
            cast = default(T);
            success = false;
        if (success)
            yield return cast;

In Mono 2.10.x, targeting .NET 4, the C# compiler gives an error on the (T)item
cast, "Unable to cast...".

If I change that line to (T)(object)item, it works.

How often does this happen? 
All the time.

Additional Information:

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

More information about the mono-bugs mailing list