c# - Loading Runtime DLL -
i'm trying load dll runtime , invoke method in 1 of classes present in dll.
here i've loaded dll , invoking method,
object[] mthdinps = new object[2]; mthdinps[0] = mscope; string paramsrvrname = srvrname; mthdinps[1] = paramsrvrname; assembly runtimedll = assembly.loadfrom("classlibrary.dll"); type runtimedlltype = runtimedll.gettype("classlibrary.class1"); object compobject = activator.createinstance(runtimedlltype, mthdinps); type compclass = compobject.gettype(); methodinfo mthdinfo = compclass.getmethod("method1"); string mthdresult = (string)mthdinfo.invoke(compobject, null);
here class(present in dll) , method i'm trying invoke,
namespace classlibrary { public class class1 { public class1() {} public string method1(object[] inpobjs) { } } }
the error i'm getting this, constructor on type 'classlibrary.class1' not found.
please help.
seems you're passing method parameters class constructor.
this:
object compobject = activator.createinstance(runtimedlltype, mthdinps);
should just:
object compobject = activator.createinstance(runtimedlltype);
and then, call method parameters:
string mthdresult = (string)mthdinfo.invoke(compobject, new object[] { objs });
Comments
Post a Comment