0

I am using dynamic method calls to access a method in a dynamically loaded dll.

I am doing:

            dynamic classInstance = Activator.CreateInstance(cmd.Type);

            classInstance.AddString();  //This line works
            classInstance.AddString(cmd);    //this line does not work

The methods in the dll are:

    public CustomCommandTest1()
    {

    }
    public void AddString(Command cmd, ExposedVariables exv)
    {
        exv.ChopResults += "Add string Command";
    }
    public void AddString(ExposedVariables exv)
    {
        exv.ChopResults += "Add string Command";
    }
    public void AddString()
    {
        string ChopResults = "Add string Command";
    }

I can access (call) all the methods that do not have parameters but those that do give me a RuntimeBindingInternalCompilerException. There is no usable info in the exception to try to figure this out.

I have done this before and it has worked. I don't know what I am doing differently here.

Further discovery here reveals that it is related to the complex variable types. Simple builtin variable types works. There is no difference in the definition of the complex variables however as I refer to the definition in a common file.

1
  • Sounds like the type your passing to the dynamic call is wrong. So like SLaks says, whats the Type of 'cmd' ? Commented Mar 22, 2011 at 12:59

3 Answers 3

2

AddString(cmd) could only work if cmd is actually an instance of ExposedVariables. There's no overload of just

public void AddString(Command cmd)

which is what it looks like you're expecting.

This has nothing to do with complex variable types - it has everything to do with you trying to call a method which doesn't exist. Which overload did you expect to be called, out of the ones you presented to us?

Sign up to request clarification or add additional context in comments.

Comments

0

If the cmd variable in your example is a reference to a Command instance rather than an ExposedVariablesinstance, then the call is wrong. You do not have an AddString overload that takes a Command only.

Comments

0

try

 ExposedVariables exv = new ExposedVariables();
 classInstance.AddString(cmd, exv);

as you don't seem to have an overload that takes just cmd.

1 Comment

You were so correct. The variations I created were for testingonly. I added it and I get the same error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.