Search code examples
stack-overflowilmerge

ILMerge StackOverflow Exception


I am trying to run ILMerge to combine my own assembly with three third party assemblies.

var ilmerge = new ILMerging.ILMerge();

ilmerge.SetInputAssemblies(new string[] {
    @"C:\dev\MyAssembly.dll",
    @"C:\dev\Nest.dll",
    @"C:\dev\Elasticsearch.Net.dll",
    @"C:\dev\Newtonsoft.Json.dll"
});

ilmerge.OutputFile = @"C:\dev\MyAssembly.Merged.dll";

ilmerge.Merge();

And am getting the following exception

An unhandled exception of type 'System.StackOverflowException' occurred in ILMerge.exe

How can I solve this?


Solution

  • In my case, a blog post by Stephen Cleary gives the answer. The .SetTargetPlatform(string, string); method should be used as below.

    var ilmerge = new ILMerging.ILMerge();
    
    ilmerge.SetInputAssemblies(new string[] {
        @"C:\dev\MyAssembly.dll",
        @"C:\dev\Nest.dll",
        @"C:\dev\Elasticsearch.Net.dll",
        @"C:\dev\Newtonsoft.Json.dll"
    });
    
    ilmerge.SetTargetPlatform("v4", @"C:\Windows\Microsoft.NET\Framework\v4.0.30319");
    
    ilmerge.OutputFile = @"C:\dev\MyAssembly.Merged.dll";
    
    ilmerge.Merge();