I basically try to call the dll by name, instantiate the object, and then call the method by name in this DLL. I get "The exception was selected as the target of the call." during the method. I am sure my problem is with typing method arguments. I was wondering if there is anyone in this exception. In addition, any suggestions on how to reconsider my approach are welcome.
public void calldll(string dllName, string typeName, string methodName, string arguments) { string[] argumentArray = arguments.Split(new char[] { '|' }, StringSplitOptions.None); Assembly assembly = Assembly.LoadFrom(dllName); System.Type type = assembly.GetType(typeName); Object o = Activator.CreateInstance(type); MethodInfo method = type.GetMethod(methodName); ParameterInfo[] parameters = method.GetParameters(); object[] methodParameters = new object[parameters.GetLength(0)]; for (int i = 0; i < parameters.Length - 1; i++) { var converter = TypeDescriptor.GetConverter(parameters[i].GetType()); methodParameters[i] = converter.ConvertFrom(argumentArray[i]); } method.Invoke(o, methodParameters); }
source share