Bug 637526 - Invalid IL code in Enumerable.cs
Summary: Invalid IL code in Enumerable.cs
Status: CONFIRMED
Alias: None
Product: Mono: Class Libraries
Classification: Mono
Component: Sys.Core (show other bugs)
Version: 2.6.x
Hardware: x86 Windows XP
: P5 - None : Normal
Target Milestone: ---
Assignee: Mono Bugs
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-07 14:33 UTC by Anindya Chatterjee
Modified: 2010-09-07 14:58 UTC (History)
1 user (show)

See Also:
Found By: Customer
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---
jbevain: needinfo? (anidotnet)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anindya Chatterjee 2010-09-07 14:33:43 UTC
Description of Problem:

I have the following function to remove a particular character from a string 

public static string Remove(this string strA, char target) 
{ 
        char[] charArr = strA.ToCharArray(); 
        var targetArr = new List<char>();	
        targetArr.AddRange( 
                        charArr.Where( 
                            character => !character.ToString(CultureInfo.InvariantCulture).Equals( 
                                target.ToString(CultureInfo.InvariantCulture), 
                                StringComparison.InvariantCultureIgnoreCase))); 
        return new string(targetArr.ToArray()); 
} 

using this function in .Net framework gives rise to 

"Hello World".Remove('l')  ---> Heo Word

but Mono throws the following exception 

System.InvalidProgramException: Invalid IL code in (wrapper delegate-invoke) System.Func`2<char, bool>:invoke_bool__this___char (char): IL_004d: castclass 0x00000007 



  at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator1D`1[System.Char].MoveNext () [0x00059] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\System.Core\System.Linq\Enumerable.cs:2305 

  at System.Collections.Generic.List`1[System.Char].AddEnumerable (IEnumerable`1 enumerable) [0x0001a] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\corlib\System.Collections.Generic\List.cs:125 

  at System.Collections.Generic.List`1[System.Char].AddRange (IEnumerable`1 collection) [0x00020] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\corlib\System.Collections.Generic\List.cs:139 

  at AbstractClass.Extensions.StringExtensions.Remove (System.String strA, Char target) [0x000de] in C:\Docs\Quasar\Quasar.Core\Extensions\StringExtensions.cs:263 

  at QuasarDemo.Tests.ExtensionTest.RunStringTest () [0x00000] in <filename unknown>:0 

  at QuasarDemo.Tests.ExtensionTest.Run () [0x00000] in <filename unknown>:0 

  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&) 

  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x000d0] in C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.7\mcs\class\corlib\System.Reflection\MonoMethod.cs:213 

Steps to reproduce the problem:
1. Compile the afore-mentioned function on Mono 2.6.7 and run it in Windows XP


Actual Results:
Calling the function is throwing the following exception

System.InvalidProgramException: Invalid IL code in (wrapper delegate-invoke) System.Func`2<char, bool>:invoke_bool__this___char (char): IL_004d: castclass 0x00000007

Expected Results:
The function should produce the following result as like .net framework

"Hello World".Remove('l')  ---> Heo Word

How often does this happen? 
Every time I compile and run the above code in Mono 2.6.7

Additional Information:
Comment 1 Jean-Baptiste Evain 2010-09-07 14:58:30 UTC
Somehow I can't reproduce that, neither on Windows nor on Linux with Mono 2.6.7 and with master.

Please provide a full test-case reproducing the error.
Comment 2 Jean-Baptiste Evain 2010-09-07 14:58:58 UTC
Working test-case:

<<<<<
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

static class Repro {

	public static string Strip(this string strA, char target)
	{
		char[] charArr = strA.ToCharArray();
		var targetArr = new List<char>();
		targetArr.AddRange(
						charArr.Where(
							character =>
								!character.ToString(CultureInfo.InvariantCulture).Equals(
									target.ToString(CultureInfo.InvariantCulture),
									StringComparison.InvariantCultureIgnoreCase)));
			return new string(targetArr.ToArray()); 
	}

	static void Main ()
	{
		Console.WriteLine ("Hello World".Strip ('l'));
	}
}
<<<<<