c# - Error 2 The type <T> exists in both... with ILMerge -


i have 3 projects:

  • a_mainproject (startup project)
  • b_intermediateproject
  • c_sharedclasslibrary

the depencies are:

a depends on b & c

b depends on c

and c depends on system only.

every project has it's own namespace.

as long no ilmerge installed, works fine.

if ilmerge activated project ("a_mainproject") still works fine , 1 self-contained executable project generated.

if ilmerge activated b_intermediateproject, following error:

error   2   type 'c_sharedclasslibrary.sharedclass' exists in both 'c:\dev\ilmergeerror\b_intermediateproject\bin\debug\b_intermediateproject.exe' , 'c:\dev\ilmergeerror\c_sharedclasslibrary\bin\debug\c_sharedclasslibrary.dll'    c:\dev\ilmergeerror\a_mainproject\program.cs    12  a_mainproject 

i use "msbuild ilmerge task" 1.0.3-rc2 "ilmerge" 2.13.0307 (from mbarnett).

the minimal solution contains 3 projects 1 class each. version has ilmerge activated on 1 project , works:

ilmergeerror_stillworking.zip

this version has activated on project b , produces error:

ilmergeerror_error.zip

if merge 2 exes , dll ilmerge externally (ilmergegui) works fine.

thank in advance answering, xan-kun

the short answer should enable ilmerge on a, it'll merge both a+b+c together.

the reason why hit error when enable ilmerge on b, b repacked c types (b' = b+c). hence when ilmerge triggers on a, it'll merge a+b'+c = a+(b+c)+c

now 2 scenarios can happen:

  1. b uses c internally, , doesn't (publicly) expose c type (e.g. method argument or return value). in case can make work through ilmerge options (/internalize on b , /allowdup on a), though you'll end twice every c type in merged assembly a.

  2. b exposes c types, maybe used a. in case if manage make merge work, it'll fail @ runtime, because , b' reference different types (e.g. class c, b' references b'.c , references c.c), , you'll nasty type cast exceptions, because 2 different types (same name, same namespace, different assemblies).

(they're nasty because don't indicate assembly mismatch, , exception says "c cannot cast c", can confusing many)


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -