question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Comapring two structs having arrays throws InvalidProgramException (“Invalid IL code”) at runtime

See original GitHub issue

If 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:closed
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
SimonCroppcommented, Apr 25, 2019

Can u try 5.0.1 beta2 of fody

1reaction
SimonCroppcommented, Apr 25, 2019

@dahlia i have deployed 5.0.1 stable, sorry for the hassle

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found