-
Notifications
You must be signed in to change notification settings - Fork 53
ILMerge. Build error. #93
Comments
Hi amid0, I'm getting the same error as you, but it's definitely not related to Newtonsoft.Json or any specific details of your code. I get a similar error whenever there is any instance of static void Main(string[] args)
{
Console.WriteLine(double.NegativeInfinity);
Console.WriteLine(double.PositiveInfinity);
Console.WriteLine(double.NaN);
} I get no errors at all, so it's not an issue with .NET 4.0. My guess is that it's related to ILMerge or DLLExport. I know for a fact that ILMerge has been deprecated and unmaintained since July 2020, so it wouldn't surprise me in the least if that was the root of this problem. I haven't done too much digging and I certainly haven't solved the problem, but the most relevant material I've found so far is as follows: and here's some documentation on an assembler that might help https://docs.microsoft.com/en-us/dotnet/framework/tools/ilasm-exe-il-assembler |
There was a bunch of .NET 6.0 syntax in the JsonTools files that needed to be removed for the code to compile in .NET framework 4.0, and it's been removed. Unfortunately there is now an error with double.NegativeInfinity, double.PositiveInfinity, and double.Nan causing compiler errors. The code works fine otherwise. See kbilsted/NotepadPlusPlusPluginPack.Net#93
So I have a hacky but functional solution if you need NaN or infinity in your code: generate it at runtime in such a way that the compiler doesn't get angry.
Here's a class that does what you want. using System;
namespace YourNameSpace
{
public class NanInf
{
/// <summary>
/// a/b<br></br>
/// may be necessary to generate infinity or nan at runtime
/// to avoid the compiler pre-computing things<br></br>
/// since if the compiler sees literal 1d/0d in the code
/// it just pre-computes it at compile time
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static double Divide(double a, double b) { return a / b; }
public static readonly double inf = Divide(1d, 0d);
public static readonly double neginf = Divide(-1d, 0d);
public static readonly double nan = Divide(0d, 0d);
}
} By the way, I've made a pull request to add this to the plugin pack! |
is there a good substitute for ilmerge @molsonkiko |
IlRepack bills itself as a good alternative, and it has been updated as recently as April 2022. No idea if it's compatible with .NET 4.0 though. I haven't done too much investigation because switching from IlMerge to something else probably requires more work than this one problem merits. |
Fix issue kbilsted#93 Add simple test (that also functions as a warning to devs) in Demo.cs
Trying to use MSBuild.ILMerge.Task nuget package to merge Newtonsoft.Json package into main dll.
On build getting error
1>D:\sources\NppPlugin\MyPlugin\MyPlugin\PluginInfrastructure\DllExport\NppPlugin.DllExport.targets(13,5): error : D:\sources\NppPlugin\MyPlugin\MyPlugin\PluginInfrastructure\ScintillaGateway.cs(16707566) : error : syntax error at token '-' in: IL_0027: ldc.r8 -inf
Sometimes it fails on other classes from \PluginInfrastructure folder
Target Framework: .NET Framework 4.5
The text was updated successfully, but these errors were encountered: