0

I have two assemblies with the exact same interface (lets call them Assem1 and Assem2)

Is it possible to use extern alias in order to call methods of Assem1 from Assem2?

The source code is something like this:

//Pre steps - set Reference in Assem1 to assem2 and set it's alias to Assem2Alias
//Both assemblies named MyAssembly.dll, has exact same interface but different Guids

//Assem1 code

extern alias Assem2;

using Assem2 = Assem2Alias.MyAssembly;

namespace MyAssembly
{
    public class MyClass
    {
        public int Foo()
        {
           return new Assem2.MyClass().Foo();
        }
    }
}
//Assem2 code
namespace MyAssembly
{
    public class MyClass
    {
        public int Foo()
        {
           return 10;
        }
    }
}

Edited: As requested - I'm adding extra information regard the general task:

I need to test application that uses ActiveX.exe to get data (responses) from external services. My task is to replace this ActiveX.exe so I will control the responses. Since the responses are large textual data, I would to generate the request using the original ActiveX.exe file.

The new assembly (Assem1 in my question) must have the exact same interface as the original ActiveX.exe (Assem2). The general idea: Assem1 gets a request from the tested application. If the request matches response in its data source --> it read the response and return it to the application. If it does not match any of the responses, then Assem1 requests Assem2 for response, adds it to its data source and response to the tested application.

As mentioned both must have the exact same interface, so I uses extern alias to refer to the original ActiveX.exe. All the examples on the internet using extern alias in C# specified to one assembly refering to two assemblies with the same interface, but not from one to each other.

Roi Shabtai
  • 2,831
  • 2
  • 28
  • 43
  • What is your intend? Maybe anyone can answer with a much cleaner architecture... – eFloh Sep 21 '11 at 14:53
  • I need to create mock manager for application testing (imitates exe service). This object gets user requests and returns responses, according to request parameters, from its data source. When it cannot find the relevant response it uses external service to generate this data. – Roi Shabtai Sep 21 '11 at 15:06
  • 3
    I see no reason why that would not work. **What happened when you tried it**? – Eric Lippert Sep 21 '11 at 16:11
  • @EricLippert: Sorry for the late response. The problem was that after referring to the first assembly, the second assembly cannot be referenced any more (during runtime). The reason for that is the registration of the first. The solution is to un-register the objects before any call. – Roi Shabtai Apr 18 '12 at 06:31
  • I thin it is possible if two assemblies hav different names. – isaeid Mar 05 '19 at 14:29
  • Possible duplicate of [Need a way to reference 2 different versions of the same 3rd party DLL](https://stackoverflow.com/questions/11550981/need-a-way-to-reference-2-different-versions-of-the-same-3rd-party-dll) – Orace Nov 20 '19 at 11:22

0 Answers0