Use a class object in different versions of the same assembly using Reflection

I have a requirement to load an assembly from another version (I already have an assembly with the same name in my application).

I managed to load the assembly and load the method that I need to call using reflection, but when I go to call the method by passing the class object as an argument, I got an exception that the class object cannot be converted to the argument parameter type.

Code Example -

Assembly myAssembly = Assembly.LoadFrom("Assembly Path for assembly with different version");
object classObject = myAssembly.CreateInstance("ClassName");
Type classType = myAssembly.GetType("ClassName");
MethodInfo myMethod = classType.GetMethod("MyMethod", BindingFlags.Instance);

// Creating an object of class in the latest assembly and need to pass this
// to method in assembly with different version.
ClassInBothVesions parameter = new ClassInBothVesions();

myMethod.Invoke(classObject, new object[] { parameter });

Here, the parameter is the object of the class that I have in the assembly, but since the parameter class is created in the assembly of the current version. And when I try to pass it to the previous build method, I got an exception that cannot be converted.

? , . .

+5
1

Framework Managed Extensibility Framework (MEF). , , AppDomains .

Edit:

, , . - , MEF . , , .Net, .

:

  • ( A).

  • ( C).

  • Remote Loader, -/ AppDomain.

  • -, .

  • B, - .

:

  • A.

  • AppDomain.

  • " " AppDomain B.

    . , B AppDomain.

  • " " C , AppDomain.

  • , , , (, ?), - .

+2

All Articles