visual studio 2015 - How do I diagnose and remove an ambiguous reference in C#? -


(please feel free suggest more accurate title question.)

in visual studio 2015 solution, have 3 projects (let's call them alpha, beta, , gamma) more or less same thing, differ in define different backends. both of these projects hot-plug class same namespace:

alpha:

namespace sharednamespace {     public class sharedclass {         // implement sharedclass using alpha's backend     } } 

beta:

namespace sharednamespace {     public class sharedclass {         // implement sharedclass using beta's backend     } } 

gamma:

namespace sharednamespace {     public class sharedclass {         // implement sharedclass using gamma's backend     } } 

several projects use hot-plugged class, each referencing either alpha, beta, or gamma. 1 of them (let's call omricon) used reference alpha, references gamma:

// ... sharednamespace.sharedclass sharedclass; sharedclass.dothing(); // ... 

when attempt build omricon, however, c# compiler gives error cs0433:

the type 'sharedclass' exists in both 'alpha, version=0.0.0.0 (etc)'  , 'gamma, version=0.0.0.0 (etc)' 

however, omricon only references gamma when built - when go project references list, reference gamma appears. far understand it, omricon should know nothing alpha @ all, less defines class in same location. omricon fails build - other projects use alpha , beta work fine, , when switch omricon using alpha, works fine well!

it appears me reference alpha being maintained, then, somewhere else. how can find stray reference alpha, wherever lies in code, , remove it?

note have tried forcing full rebuild (as this answer suggested), , same error still appears, has nothing bad object caching.

edit: clarified second last paragraph

first off, have realized: this terrible situation in. if can possibly avoid having same named class in same named namespace in 2 different assemblies reference both of them, avoid situation. indicative of architectural flaw in application. sounds me should defining interface in yet fourth assembly, , have assemblies agree use interface.

however, there is way deal situation in c#.

when compile omicron, should give alpha.dll, beta.dll , gamma.dll reference alias:

/reference:alphadll=alpha.dll /reference:betadll=beta.dll ... etc 

then inside omicron say:

extern alias alphadll; extern alias betadll; extern alias gammadll; 

in file, , later in file can say:

alphadll::sharednamespace.sharedclass 

in order disambiguate 1 intended.

but again, do not situation. instead make interface sharedclass implements, , have alpha, beta , gamma implementations implement interface class name not conflict.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -