13

I have an solution with a number of projects. Relevant for the question is an API class library, a CustomTriggers class library and a web site. Both CustomTriggers and web site references API. CustomTriggers implements Interface ITrigger located in API.

The problem is that if I in the 'Run' method of the interface ITrigger defines one parameter things work ok, but if I define two parameters a "Method 'Run' in Type 'CustomTriggers.*' from assembly * does not have an implementation' exception is thrown. And I don't understand why.

The interface:

namespace projectbase{
public interface ITrigger {
    string EntityTypeName { get; set; }
    int EntityID { get; set; }
    API.API.TriggerEventType TriggerEventType { get; set; }
    void Run(KeyValuePair<string, object>[] parameters);
}  }

The class in 'CustomTriggers' project that implements ITrigger:

public class SomeTrigger : projectbase.ITrigger {
    public string EntityTypeName { get; set; }
    public int EntityID { get; set; }
    public API.API.TriggerEventType TriggerEventType { get; set; }
    public void Run(KeyValuePair<string, object>[] parameters) {
    }
}

The method [stub] that [doesn't] throw exception:

string file = @"dir\CustomTriggers.dll";
string assemblyname = AssemblyName.GetAssemblyName(file).ToString();
Assembly ass = Assembly.Load(assemblyname);
Type assType = null; // funny! :-)

if (ass != null)
    assType = ass.GetType("CustomTriggers.SomeTrigger", false); //throws exception here :-(
if (assType != null) {
    foreach (Type t in assType.GetInterfaces()) {
        if (t.Name == "ITrigger") {
            blnValidTypeFound = true;
            break;
        }
    }
} // if

So...this code complies and runs just fine. No worries in sight.

But when I add another parameter to the 'Run' method of both 'ITrigger' and 'SomeTrigger'

void Run(KeyValuePair<string, object>[] parameters, string OtherParameter);

public void Run(KeyValuePair<string, object>[] parameters, string OtherParameter) {}

it throws an exception in the line indicated by a comment:

Method 'Run' in type 'CustomTriggers.SomeTrigger' from assembly 'CustomTriggers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation.

I'm all out of ideas. Little help?

volapture
  • 131
  • 1
  • 1
  • 4
  • Some more information could be useful, where is the exception thrown? – Felix K. Nov 15 '11 at 09:06
  • 2
    Did you recompile everything after the change? In particular whenever you add a method to the interface, you should recompile the implementing class afterwards. – CodesInChaos Nov 15 '11 at 09:09
  • What is the exception thrown? – YogevSitton Nov 15 '11 at 09:25
  • Exception is thrown in the '.GetType("CustomTriggers.SomeTrigger", false);" line. I've added a comment line to indicate where. I pay special attention to recompling, in correct order, after changes. The full exception thrown is: Method 'Run' in type 'CustomTriggers.SomeTrigger' from assembly 'CustomTriggers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. – volapture Nov 15 '11 at 10:11

0 Answers0