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);
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.
? , . .