The function is as follows. For more information, see :)
Note:
1. ReturnMessage is a self-written class. For more information, see my other articles.
2. You can use NameSpaceAndClassName and MethodName to precisely locate a method, such as calling abc. namespace1.Class1 in dll. main, called CallAssembly ("abc. dll "," namespace1.Class1 "," Main ", null)
Public static ReturnMessage CallAssembly (string Path, string NameSpaceAndClassName, string MethodName, object [] Parameters)
{
Try
{
Assembly Ass = Assembly. LoadFrom (Path); // call a file (not limited to dll, exe, as long as it is. net)
Type TP = Ass. GetType (NameSpaceAndClassName); // NameSpaceAndClassName is "namespace. Class Name", for example, "namespace1.Class1"
MethodInfo MI = TP. GetMethod (MethodName); // MethodName is the name of the method to be called, such as "Main"
Object MeObj = System. Activator. CreateInstance (TP );
MI. Invoke (MeObj, Parameters); // Parameters is the list of Parameters passed in when the target method is called.
Return new ReturnMessage (true, "successful call", 1 );
}
Catch (Exception e)