Using Double.Nan can cause SetAsmInfo to fail
This code will cause it to fail:
public class Utils
{
// this produces invalid IL code during SetAssemblyInfo.
public double Value => double.NaN;
}
This generates the following IL code which is not valid:
IL_0000: ldc.r8 -nan(ind)
The issue was introduced in .NET 4.8 and can probably be fixed by search/replace -nan(ind) for something else. I suggest we just dont use 4.8.
A quick patch can be done by using the code below:
namespace NanTest
{
public class Utils
{
// this produces invalid IL code during SetAssemblyInfo.
//public double Value => double.NaN;
// do this instead:
static double zero = 0.0;
public static double Value => zero / zero;
}
public class Program
{
public static void Main()
{
if (double.IsNaN(Utils.Value))
{
Console.WriteLine("NAN");
}
else
{
Console.WriteLine("NOT NAN");
}
}
}
}
Replace ment values:
// these codes are invalid
IL_0000: ldc.r8 -nan(ind)
IL_0000: ldc.r8 -inf
IL_0000: ldc.r8 inf
IL_0000: ldc.r4 -nan(ind)
IL_0000: ldc.r4 -inf
IL_0000: ldc.r4 inf
// replace with these
IL_0000: ldc.r8 (00 00 00 00 00 00 F8 FF)
IL_0000: ldc.r8 (00 00 00 00 00 00 F0 FF)
IL_0000: ldc.r8 (00 00 00 00 00 00 F0 7F)
IL_0000: ldc.r4 (00 00 C0 FF)
IL_0000: ldc.r4 (00 00 80 FF)
IL_0000: ldc.r4 (00 00 80 7F)
Related MS issues:
Edited by Rolf Madsen