Search code examples
.netilmerge

ILMerge error: Key needs to be greater than 0


We have a step on our build server that merges our DLLs into one for easy transport.

In our QA environment, we are getting the following error when running ILMerge

An exception occurred during merging:
Key needs to be greater than 0.
Parameter name: key
   at System.Compiler.TrivialHashtable.get_Item(Int32 key)
   at System.Compiler.Ir2md.GetTypeSpecIndex(TypeNode type)
   at System.Compiler.Ir2md.GetMemberRefIndex(Member m)
   at System.Compiler.Ir2md.GetMethodToken(Method m)
   at System.Compiler.Ir2md.VisitConstruct(Construct cons)
   at System.Compiler.Ir2md.VisitAssignmentStatement(AssignmentStatement assignment)
   at System.Compiler.Ir2md.VisitBlock(Block block)
   at System.Compiler.Ir2md.VisitBlock(Block block)
   at System.Compiler.Ir2md.VisitMethodBody(Method method)
   at System.Compiler.Ir2md.VisitMethod(Method method)
   at System.Compiler.Ir2md.VisitClass(Class Class)
   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 ILMerging.ILMerge.Merge()
   at ILMerging.ILMerge.Main(String[] args)

Any ideas how this can be fixed? We have too much code and too many DLLs for it to be useful for me to provide any more info about what DLLs we're trying to merge.

The code being merged was branched off of our development line this morning- the code is identical to the development line, which is able to ILMerge just fine.

The merge error is occurring on our local machines as well as our build server.

I know this isn't a lot to go on, but it's all I've got!

After building the code in Release mode, IL merge works properly.


Solution

  • Not exactly an answer, but you can give a try at ILRepack, it has an identical syntax to ILMerge, but the code is open-source, and the exception (if any) may be more explicit (no guarantee though).

    Also if your target assembly is signed, maybe the 'key' refers to its signing key somehow, in case it helps put you on some track.