Search code examples
.netcompiler-errorscilintermediate-language

Unrecoverable IL error, but the IL looks fine


I'm getting errors with the following IL. Any idea why? It looks fine to me!

enter image description here

The issue is with the lines stloc.4/ldloc.4 that are highlighted in bold.

The syntax highlighting is from Rider, but I get the same issue with ilasm as well.

I'm running this on MacOS.


Solution

  • Problem is that there's no stloc.4, stloc.x goes up to 3. You should use stloc followed by number, e.g. stloc 4. Since index of variable is less than 255, it's possible to use stloc.s 4 to save few bytes in resulting assembly. Same applies to ldloc.4 at next line