Missing references while calling another application method using reflection

184 views Asked by At

I am trying to call a method in winForms application from a command line application using reflection. This method launches the application with loaded configuration.

Assembly exeApp = Assebmly.LoadFile(exeAppPath);
Type classType = exeApp.GetType(nameSpace);
object obj = classType.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
MethodInfo exeMethod classType.GetMethod(MethodName);

exemethod.Invoke(obj, args);

Using this, I am able to call the method, but I get following exception for all referenced assemblies in my target exe:

Exception thrown: 'System.IO.FileNotFoundException' in winFormsApp.exe
Additional information: Could not load file or assembly 'refAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified

If I add references to all those assemblies in my command line app, it works correctly.

The problem here is, the exe references keeps on changing/updating as per releases, and it makes difficult to update/release commandLine app everytime.

Is there any way I can make it work without adding the references in commandLine app ?

0

There are 0 answers