I am using ILMerge version 2.11.1103.0 to merge 4 DLL's into a new assembly. Assuming they are called A, B, C, and D, their relationships are as follows:
B -> A
C -> A
D -> A
D -> C
When I run ILMerge on A, B, and C, it all works perfectly fine. However when I add D I receive the following error:
An exception occurred during merging:
ILMerge.Merge: The assembly 'A' was not merged in correctly.
It is still listed as an external reference in the target assembly.
at ILMerging.ILMerge.Merge()
at ILMerging.ILMerge.Main(String[] args)
I have tried using the /closed option as indicated here ILMerge DLL: Assembly not merged in correctly, still listed as an external reference but unfortunately it does not help:
In order to close the target assembly, the number of assemblies to be added to the input is 0.
When I change the order of the assemblies, I receive the following exception:
An exception occurred during merging:
Index was outside the bounds of the array.
at System.Compiler.ISymUnmanagedWriter.CloseMethod()
at System.Compiler.Ir2md.VisitMethodBody(Method method)
at System.Compiler.Ir2md.VisitMethod(Method method)
at System.Compiler.Ir2md.Visit(Node node)
at System.Compiler.Ir2md.VisitClass(Class Class)
at System.Compiler.Ir2md.Visit(Node node)
at System.Compiler.Ir2md.VisitModule(Module module)
at System.Compiler.Ir2md.SetupMetadataWriter(String debugSymbolsLocation)
at System.Compiler.Ir2md.WritePE(Module module, String debugSymbolsLocation, BinaryWriter writer)
at System.Compiler.Writer.WritePE(String location, Boolean writeDebugSymbols, Module module, Boolean delaySign, String keyFileName, String keyName)
at System.Compiler.Writer.WritePE(CompilerParameters compilerParameters, Module module)
at System.Compiler.Module.WriteModule(String location, CompilerParameters options)
at ILMerging.ILMerge.Merge()
at ILMerging.ILMerge.Main(String[] args)
The full command line I'm using is:
ILMerge.exe /targetplatform:v4,"C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0" /log:ilmerge.log /target:library /union /xmldocs /copyattrs /allowMultiple /internalize /closed /keyfile:keyfile.snk /out:Merged.dll A B C D
Can anyone see what am I doing wrong? Thanks.
As suggested by @HansPassant in the comment above, I contacted Mike Barnett of Microsoft fame. He was able to help me fix this by:
Upgrading to the latest version of ilmerge (2.12.0803) from http://nuget.org/packages/ilmerge
Removing the /union switch from the command (this was previously added to resolve an issue running gendarme on merged assemblies that had been rewritten by the Code Contracts rewriter. Thankfully due to a change in the build process this was no longer required).
I've encountered issues with ILMerge not working before. I suppose they're just bugs... Try merging in multiple phases, e.g. Merge B and A in to A', then merge A' with C and D. Maybe that will produce different results/errors that might lead to a solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With