0

I am basically doing the same work as described in extern alias with same assembly file name: I am writing a converter for classes between different versions of a software, so that the XML settings of these classes can be converted.

The conversion is ready and working ("extern alias" are set where needed).
Now I want to change my small test project into a full program. The conversion uses the DLLs of V22, V23 and V24, each with respective alias, and the program should use the latest version of the DLLs (currently V24, without alias, thus global) for its own operation. The problem is, that the program does not find any types from the referenced global DLLs.

Is Visual Studio (I'm using v.2015 U3) maybe not able to distinguish between the DLLs if the same DLL is used with and without alias?

The project references:

basics, path=..\v24.., no alias (#1)
basics v=22, path=..\v22.., alias=V22
basics v=23, path=..\v23.., alias=V23
basics v=24, path=..\v24.., alias=V24 (#1)
imaging v=22, path=..\v22.., alias=V22
imaging v=23, path=..\v23.., alias=V23
imaging v=24, path=..\v24.., alias=V24
...

I supspect that the marked (#1) assemblies collide somehow.
Is this correct?

Any solution or workaround?

I could add "extern alias V24" in every file of the general part of the program, but then I'd have to change that to "extern alias V25" when the next version of the DLLs is released. I'd like to avoid that extra work.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Tobias Knauss
  • 3,361
  • 1
  • 21
  • 45

1 Answers1

0

I found an acceptable workaround.

Instead of adding the alias to every "using" when I switch to another version, e.g. replace "/* v24 */" by "swcore_v_0_22"

using CImageObject_V_0_22         = swcore_v_0_22.SwCore.CImageObject;
using CImageObject_V_0_24         = /* v24 */     SwCore.CImageObject;
using CImageObjectStandard_V_0_22 = swcore_v_0_22.SwCore.CImageObjectStandard;
using CImageObjectStandard_V_0_24 = /* v24 */     SwCore.CImageObjectStandard;
using CImageObjectCombi_V_0_22    = swcore_v_0_22.SwCore.CImageObjectCombination;
using CImageObjectCombi_V_0_24    = /* v24 */     SwCore.CImageObjectCombination;

I can simply add a nested using, which is not possible by default but possible when placed inside a different namespace, see https://stackoverflow.com/a/35921944/2505186. The namespace exists anyway.

using SwCore_v_0_22 = swcore_v_0_22.SwCore;
using SwCore_v_0_24 = global::SwCore;

namespace ConfigEditor
{
  using CImageObject_V_0_22                         /**/= SwCore_v_0_22.CImageObject;
  using CImageObject_V_0_24                         /**/= SwCore_v_0_24.CImageObject;
  using CImageObjectStandard_V_0_22                 /**/= SwCore_v_0_22.CImageObjectStandard;
  using CImageObjectStandard_V_0_24                 /**/= SwCore_v_0_24.CImageObjectStandard;
  using CImageObjectCombi_V_0_22                    /**/= SwCore_v_0_22.CImageObjectCombination;
  using CImageObjectCombi_V_0_24                    /**/= SwCore_v_0_24.CImageObjectCombination;

Later I will replace "global" by "swcore_v_0_24" in all files, which still is some work, but much less than before. And since it is replacing instead of adding, it can do it automatically.
I could theoretically also replace "/* v24 */", but that could break the nice vertical alignment depencing of the length of the replacement. ;-)

Tobias Knauss
  • 3,361
  • 1
  • 21
  • 45