ILMerge-MSBuild-Task icon indicating copy to clipboard operation
ILMerge-MSBuild-Task copied to clipboard

Key needs to be greater than 0 - possible error when running task multiple times

Open mpseidel opened this issue 6 years ago • 3 comments

This error in ILMerge can occur when using the build task multiple times in the same build.

In our case we had about 10 projects in a solution that needed to be merged individually. As the build task loads the ILMerge assembly once into the build process and ILMerge uses statics this can lead to the error Key needs to be greater than 0 explained in more detail in the referenced issue.

Our workarround was to turn on BuildInParallel and setting -maxcpucount > 1 which reduced the number of merge operations per msbuild process.

As

it [ILmerge] was definitely written as a console application that would run once and then terminate.

I would suggest a) allow the option to spawn a new ILMerge process per merge operation or b) load ILMerge into a secondary AppDomain and unload it after the merge or c) maybe consider a upstream fix if possible.

This issue has caused us quite some pain as builds were failing seemingly randomly so I hope someone else finds this and can save themselves some headache.

mpseidel avatar May 10 '19 05:05 mpseidel

Thanks a bunch for investigating the issue and taking the time to post it here. I went trough the ticket you provided in the ILMerge project and it is very helpful - looks like you guys covered it in details in there.

I will see what I can do here and get back to you.

emerbrito avatar May 13 '19 12:05 emerbrito

Just wanted to let you know I'm still looking into this. Hopefully will be able to get to a conclusion in a few weeks.

emerbrito avatar Jun 18 '19 14:06 emerbrito

Thats great to hear. Even though we are using multiple msbuild processes now yesterday we ran into the error again. Good thing is this led us to do an overdue depenency reorganization which reduced the amount of merging work but still would be great to know this is solved for good at some point :)

mpseidel avatar Jun 19 '19 06:06 mpseidel