Reputation: 97
This is my class in a C# DLL
namespace MyNS
{
public class MyClass
{
public static int Execute(string logKey,
string key,
XmlNode xmlPars)
{
return 0
}
}
}
I load DLL at run time and load Class Type in to _type variable. But when I call the function Execute from a Windows service like this:
counter = (int)_type.InvokeMember("Execute",
BindingFlags.Public |
BindingFlags.InvokeMethod |
BindingFlags.Static,
null,
null,
new object[] {
logKey,
Key,
_xmlParams
});
I get "Exception has been thrown by the target of an invocation."
What did I do wrong here?
Upvotes: 0
Views: 921
Reputation: 1541
How you are loading the the DLL, can you please share the code to load the dlls dynamically.?
Here's the sample code.
Assembly assembly = Assembly.LoadFrom("ABC.dll");
object o = Activator.CreateInstance(assembly.GetType("ClassName"));
/// then invoke the method
Upvotes: 1