Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 550
Dean Avatar asked Aug 13 '14 04:08

Dean


2 Answers

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

like image 104
Tintifax Avatar answered Nov 06 '22 23:11

Tintifax


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!

like image 34
Dany Gauthier Avatar answered Nov 06 '22 23:11

Dany Gauthier