10

I'll make this as simple as I can, if you need any more info please let me know. I downloaded ILMerge to merge Newtonsoft.Json.dll into my class library. I am invoking ILMerge from the post-build event command line with the following:

"$(ProjectDir)bin\ILMerge.exe" /internalize:"$(ProjectDir)bin\ILMergeIncludes.txt" /out:"$(TargetDir)$(TargetName).all.dll" "$(TargetDir)$(TargetName).dll" "$(TargetDir)*.dll" /target:library /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /wildcards

In the output window it says:

An exception occurred during merging:
  ILMerge.Merge: ERROR!!: Duplicate type 'myLibrary.some.class' found in assembly 'myLibrary.all'. Do you want to use the /alllowDup option?
     at ILMerging.ILMerge.MergeInAssembly(AssemblyNode a, Boolean makeNonPublic, Boolean targetAssemblyIsComVisible)
     at ILMerging.ILMerge.Merge()
     at ILMerging.ILMerge.Main(String[] args)

The problem is that 'myLibrary.some.class' is NOT a duplicate.

I've been all over the internet looking for clues and all I've turned up is the following 2 links, and a few cases of web apps where people have copy/pasted pages and forgot to change the class names.

similar problem with a solution that doesn't seem relevant

same cry for help but with no answers

I've tried using the allowDup option but in the merged dll it turns 'myLibrary.some.class' into 'myLibrary.some.random125624.class'. Then I tried using allowDup passing in 'class' but then I get "Duplicate type" errors for 'class2' and then 'class3' and then 'class4'... there seems to be no end to the number of duplicate types!

I'm certain these classes are not duplicates as the namespace is very specific to my company and project.

Can anyone help?

Dean
  • 4,554
  • 7
  • 34
  • 45
  • I've decided that using ILMerge is just not a good idea. Sorry co-worker, but you'll just have to live with multiple dll's – Dean Aug 13 '14 at 05:53
  • Your link to "similar problem with a solution that didn't seem relevant" helped me. Passing the -fixednames argument to the aspnet_compiler got me past this problem when merging. – eric1825 Feb 03 '16 at 10:06

3 Answers3

2

In your command line you tell ILMerge to use one library tiwce
ILMerge takes all dll-filese in the TargetDir with "$(TargetDir)*.dll" /wildcards and once again you add the file "$(TargetDir)$(TargetName).dll".

So the solution is very simple. Try this commandline:
"$(ProjectDir)bin\ILMerge.exe" /internalize:"$(ProjectDir)bin\ILMergeIncludes.txt" /out:"$(TargetDir)$(TargetName).all.dll" "$(TargetDir)*.dll" /target:library /targetplatform:v4,C:\Windows\Microsoft.NET\Framework64\v4.0.30319 /wildcards

Tintifax
  • 201
  • 1
  • 5
1

I had the same problem, using Fody (https://github.com/Fody/Costura) worked for me.

Make sure you set it up correctly to remove all unnecessary files after build (Creating a clean output directory Section) and you'll have a single dll or exe.

Hope it helps!

Dany Gauthier
  • 800
  • 6
  • 16
0

I know this is an ancient question, but it's the first google gives back for this error (for me anyway).

Nowadays, for me, the cheap and nasty solution is to simply add "/union" to the options on the command line.

EmFinn
  • 1
  • 2