0

Please correct me if the terminology is incorrect.

I'm loading an assembly at runtime and running a method from it. The return part is where I'm having trouble.

string path = @"C:\path\to\class.dll";
Assembly assembly = Assembly.LoadFrom(path);
Type runner = assembly.GetType("NameSpace.Class");
object instance = = Activator.CreateInstance(runner);
MethodInfo myMethod = runner.GetMethod("Method");
TestResultModel result = await (Task<TestResultModel>)myMethod.Invoke(instance, new object[] { param1, param2, param3 });

MethodA looks like:

public async Task<TestResultModel> MethodA(dynamic param1, dynamic param2, dynamic param3)
    {
        //do something
        TestResultModel.TestString = "test"
        TestResultModel.ReturnString = "test Return"
        return TestResultModel
    }

The TestReturnModel.cs is in both the main program and the .dll being loaded, it looks like:

public class TestResultModel
    {
        public string ResultString { get; set; }
        public string TestString { get; set; }
    }

I've tried making result an object and dynamic, but am either unable to access the data or get an exception thrown. I would like the data from MethodA returned as I have structured in the TestResultModel. Is there a way to do this?

0 Answers0