Bugzilla – Bug 637526
Invalid IL code in Enumerable.cs
Last modified: 2010-09-07 14:58:58 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:
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.
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')); } } <<<<<