[Mono-bugs] [Bug 662174] New: Invalid IL exception when using foreach and casting to IEnumerable<object>

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Jan 3 23:00:33 EST 2011



           Summary: Invalid IL exception when using foreach and casting to
    Classification: Mono
           Product: Mono: Runtime
           Version: 2.8.x
          Platform: x86-64
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: generics
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: earlz at earlz.biz.tm
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---

User-Agent:       Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:
Gecko/20101211 Firefox/3.6.13

While trying to make a generic T4 template dealing with some variables I ran
into this Invalid IL problem. 

The relevant code:

string Title="...";
StreamWriter __Output=....

    var v=Title;
    Type t = v.GetType();
    if (t.IsGenericType && t.GetGenericTypeDefinition() ==
       foreach(var item in (IEnumerable<object>)v)
__Output.Append(item.ToString()); //error here

The error goes away if I comment out the foreach loop line. 

I am on an x86-64 install of Arch Linux using up to date Mono packages.
It happened in an ASP.Net application. The using list is

using System;
using System.Core;
using System.Generics.Collections;

Reproducible: Always

Steps to Reproduce:
Use the provided code. 
Actual Results:  
An Invalid IL exception:

Invalid IL code in EViewEngine.TestView:BuildOutput (): IL_0105: castclass

Expected Results:  
It should have skipped over this code because Title in this case was a string.

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