Help with Type.InvokeMember in C#

L

Laurent

Hello,

I'm having a problem trying to call a DLL assembly from a C# code with
some special parameters.

I have a global class used to store some parameters and work with them:

public class GlobalClass
{
public int parameter1;
public string parameter2;

public void Method1()
{
}
}


Then I made a class for my PlugIn, which instanciate the GlobalClass
class in a method:

Public class PlugIn
{

public void Method1(GlobalClass testClass)
{
...
}
}


Finaly, I have a test class which calls the PlugIn.Method1() method
using the InvokeMember method:

Public class Test
{

public void TestFunction()
{
Assembly plugin;
Type typeAssembly;
GlobalClass globalClass = new GlobalClass();

plugin = Assembly.LoadFrom("Test.dll");
typeAssembly = plugin.GetType("PlugIn");
object instancePlugin = Activator.CreateInstance(typeAssembly);
object arguments = { globalClass };

typeAssembly.InvokeMember("Method1", BindingFlags.InvokeMethod,
null, instancePlugin, arguments);
}


When I execute this code, I got an exception "Method not found".
I also tried to use a ref and a ParameterModifier, but I have the same
exception.
I also tried to use the GlobalClass as return value of the
PlugIn.Method1() method, but then I'm not able to cast back the
System.Object returned by the InvokeMember() method to GlobalClass.

Can someone help me ? I'd be really gratefull !!! :)


Laurent
 
B

Bruce Wood

Could you post the exact error message you get, and indicate at which
line of code you're getting it?
 
L

Laurent

Wow, thanks !!

I used the second solution that was written in your web page, and
everything is working fine. Even if now I must compile in DOS, I'm happy.

Thank you very much for your help, and thanks to Bruce Wood too ! :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top