Dean
Dean

Reputation: 4604

ILMerge.Merge: ERROR!!: Duplicate type found in assembly

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?

Upvotes: 11

Views: 12389

Answers (3)

EmFinn
EmFinn

Reputation: 1

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.

Upvotes: 0

Tintifax
Tintifax

Reputation: 211

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

Upvotes: 2

Dany Gauthier
Dany Gauthier

Reputation: 800

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!

Upvotes: 1

Related Questions