ILASM problem when dealing with double NaN and Inf

789 Views Asked by At

I create a simple program with a double type value initialized,

var a = double.NaN;

I build the project with Visual Studio 2019, .net framework 4.5 and disassemble it into a .il file using ILDASM.exe Version 4.0.30319.0

IL_0001: ldc.r8 -nan(ind)

but there is an error when I try to assemble it using ILASM.exe Version 4.8.3752.0

test.il(65) : error : syntax error at token '-' in: IL_0001: ldc.r8 -nan(ind)

This happened to Double.PositiveInfinity and Double.NegativeInfinity too. Anyone can help?

2

There are 2 best solutions below

2
On BEST ANSWER

I found the error reason from here

and the simple solution is just to replace the:

ldc.r8 -nan(ind) -> ldc.r8 (00 00 00 00 00 00 F8 FF)

ldc.r8 inf -> ldc.r8 (00 00 00 00 00 00 F0 7F)

ldc.r8 -inf -> ldc.r8 (00 00 00 00 00 00 F0 FF)

0
On

I was able to get around this by copying ildasm from an older machine. "c:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools"

My new machine only had "c:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools" and i renamed ildasm.exe and added the 4.6 one.