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

I will make it as simple as possible, if you need more information, please let me know. I downloaded ILMerge to combine Newtonsoft.Json.dll into my class library. I call ILMerge from the command line events after the build 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 

The output window 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 searched around the internet for clues, and all I found was the following 2 links and several cases of web applications in which people copied / pasted pages and forgot to change class names.

similar problem with a solution that does not seem relevant

same cry for help but no answers

I tried using the allowDup parameter, but in the combined dll, it turned 'myLibrary.some.class' into 'myLibrary.some.random125624.class'. Then I tried to use 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 am sure that these classes are not duplicates, as the namespace is very specific to my company and project.

Can anyone help?

+5
source share
2 answers

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

Make sure that you correctly configured to delete all unnecessary files after assembly (creating a clean section of the output directory), and you will have one dll or exe.

Hope this helps!

+1
source

On the command line, you tell ILMerge to use a single tiwce library
ILMerge accepts all dll files in TargetDir using "$(TargetDir)*.dll" /wildcards and again you add the file "$(TargetDir)$(TargetName).dll" .

Therefore, the solution is very simple. Try this command line:
"$(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

0
source

Source: https://habr.com/ru/post/1200177/


All Articles