2
Vote

Bug in GenerateEqualsMethod (AnonymousTypes.cs)

description

An exception occurs when retrieving a dynamic type with more than 5 properties, e.g:
 
var items = _someService.Query()
                    .Select(x=>
                        new
                        {
                            Name = x.Name,
                            Age = x.Age,
                            Gender = x.Gender,
                            Species = x.Species,
                            ID = x.IDNumber,
                            Blah = x.Whatever
                        }
                        )
                    .ToList();
 
The exception thrown is:
System.NotSupportedException
"Illegal one-byte branch at position: 9. Requested branch was: 144."
 
The cause seems to be in the extension method GenerateEqualsMethod (AnonymousTypes.cs), line 374:
ilGen.Emit(OpCodes.Brfalse_S, falseLabel);
 
I don't really know whats going on in there, but I think the label is too large (>1byte) or something, so then the Op fails. Anyway, changing the Opcode to Brfalse (which can accept int<32>), seems to fix the problem:
 
ilGen.Emit(OpCodes.Brfalse, falseLabel);

comments