Not sure if the subject describes my question very well. But here's the
info.
I've wrote a windows 2000 service. One of it's classes implements certain
Interface (IMaster).
Upon initiaization Windows 2000 service loads a plugin written in CSharp,
compiles it on the fly, loads the result assembly and trys to invoke a
certain method via Reflections.
Method in question requires a parameters of type IMaster (passing Service
object reference to the plugin).
In order for plugin to compile, it declares IMaster interface in it's
source, jsut like the Windows 2000 service does in it's source. Namespaces
are identical.
The problem I have is when i try to invoke that method from the windows
2000 service, i get following error:
System.ArgumentException: Object type cannot be converted to target type.
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj,
BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo
culture, Boolean verifyAccess)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
Here are the source code excerpts:
[Windows 2000 Service]
public interface IMaster
{
void SendMessage(string pMessage);
void Close();
}
public class Master() : IMaster
{
Assembly assembly = Assembly.LoadFrom(....some path ....);
Type type = assembly.GetTypes()[0];
MethodInfo mi = type.GetMethod("SendMessage");
object[] paramArray = new object[2];
paramArray[1] = (IMaster) this;
paramArray[0] = "Test message";
mi.Invoke(null, paramArray);
}
[Plugin source]
public interface IMaster
{
void SendMessage(string pMessage);
void Close();
}
public class Master
{
private Master() { }
public static void SendMessage(IMaster pMaster, string pMessage)
{
pMaster.SendMessage("ECHO");
pMaster.Close();
}
}
Any ideas what am I doing wrong?
Thanx.