Load assembly interface without sharing common library

93 Views Asked by At

I was wondering if the common library needs to be shared between assemblyA and assemblyB. What needs to be achieved is loading assemblyA inside assemblyB code and cast the interface as below after loading (from object) one of the types. I read about condition such as some sort of parent class / interface shared between the two interfaces defined in each assembly A and assembly B. Can we somehow achieve the complete decoupling without having to have to share some type of common library?

IInterfaceA
{
   string name {get; set;}
   int  age {get; set;}
   MethodA(int a);
   MethodB(int b);
}

The current code bringing in assemblyA during run time would look like:

var assembly = Assembly.LoadFrom(mainAssemblyName);
var type = assembly.GetTypes().Single(type => type.Name.Equals("InterfaceA"));
var casted = (InterfaceA)Activator.CreateInstance(type);
0

There are 0 best solutions below