Comapring two structs having arrays throws InvalidProgramException (“Invalid IL code”) at runtime
See original GitHub issueIf a struct having array properties comparing two values of that type throws InvalidProgramException
at runtime. The minimum reproducible code is here:
using System;
[Equals]
public struct FooBar {
public FooBar(int[] foo, int[] bar) {
Foo = foo;
Bar = bar;
}
public int[] Foo { get; set; }
public int[] Bar { get; set; }
}
public class Program {
static void Main(string[] args) {
var a = new FooBar(new[] { 1, 2 }, new[] { 3, 4 });
var b = new FooBar(new[] { 1, 2 }, new[] { 3, 4 });
if (a.Equals(b))
{
Console.WriteLine("They equal.");
}
}
}
This program crashes with an unhandled exception:
Unhandled Exception:
System.InvalidProgramException: Invalid IL code in FooBar:EqualsInternal (FooBar,FooBar): IL_0002: bne.un.s IL_0010
at FooBar.Equals (System.Object obj) [0x0003a] in <9c04883983e745dcaee8439101d7e69a>:0
at Program.Main (System.String[] args) [0x00047] in <9c04883983e745dcaee8439101d7e69a>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidProgramException: Invalid IL code in FooBar:EqualsInternal (FooBar,FooBar): IL_0002: bne.un.s IL_0010
at FooBar.Equals (System.Object obj) [0x0003a] in <9c04883983e745dcaee8439101d7e69a>:0
at Program.Main (System.String[] args) [0x00047] in <9c04883983e745dcaee8439101d7e69a>:0
On the other hand, this runtime exception does not occur if it’s not a struct
but a class
.
I ran the above program on Mono 5.20.1.19 & macOS 10.14.2.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Recently Active 'c#' Questions - Page 15204
InvalidProgramException (Invalid IL Code)?. I was trying to emit the following code as IL code at runtime. class TestObject { public int Hello...
Read more >Mono 4.4.0 Release Notes
The folder structure on disk when installing Mono now looks like this: ... InvalidProgramException: Invalid IL code; #36339 - Stepping is ...
Read more >mono-data-6.8.0-bp153.1.194 RPM for x86_64
FullPath throws ArgumentNullException * gh#mono/mono#16712 - SIGSEGV in ... Nullable structs with implicit operators generate invalid IL code when compiling ...
Read more >mono-core-6.8.0-bp152.4.6
Various sets of issues with the debugger have been resolved in this release ... structs with implicit operators generate invalid IL code when...
Read more >.NET 2.0 IL Assembler - GitHub
ILAsm has two keywords, value and enum, that can be placed among the class flags to ... possibly indicates invalid IL code. A...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Can u try 5.0.1 beta2 of fody
@dahlia i have deployed 5.0.1 stable, sorry for the hassle