title: Activator.CreateInstance can't find the constructor (MissingMethodException)
body: <p>I have a class which has the following constructor</p>
  
  <pre><code>public DelayCompositeDesigner(DelayComposite CompositeObject)
  {
      InitializeComponent();
  
      compositeObject = CompositeObject;  
  }
  </code></pre>
  
  <p>along with a default constructor with no parameters.</p>
  
  <p>Next I'm trying to create an instance, but it only works without parameters:</p>
  
  <pre><code>var designer = Activator.CreateInstance(designerAttribute.Designer);
  </code></pre>
  
  <p>This works just fine, but if I want to pass parameters it does not:</p>
  
  <pre><code>var designer = Activator.CreateInstance(designerAttribute.Designer, new DelayComposite(4));
  </code></pre>
  
  <p>This results in an <code>MissingMethodException</code>:</p>
  
  <blockquote>
    <p>Constructor voor type
    Vialis.LightLink.Controller.Scenarios.Composites.DelayCompositeDesigner
    was not found</p>
  </blockquote>
  
  <p>Any ideas here?</p>
  
  <hr>
  
  <p>The problem is I really need to pass an object during construction.</p>
  
  <p>You see I have a designer which loads all the types that inherit from the <code>CompositeBase</code>. These are then added to a list from which the users can drag them to a designer. Upon doing so an instance of the dragged is added to the designer. Each of these classes have custom properties defined on them:</p>
  
  <pre><code>[CompositeMetaData("Delay","Sets the delay between commands",1)]
  [CompositeDesigner(typeof(DelayCompositeDesigner))]
  public class DelayComposite : CompositeBase
  {
  }
  </code></pre>
  
  <p>When the user selects an item in the designer, it looks at these attributes in order to load up a designer for that type. For example, in the case of the <code>DelayComposite</code> it would load up a user control which has a label and a slider which allow the user to set the "Delay" property of the <code>DelayComposite</code> instance.</p>
  
  <p>So far this works fine if I don't pass any parameters to the constructor. The designer creates an instance of the <code>DelayCompositeDesigner</code> and assigns it to the content property of a WPF <code>ContentPresenter</code>.</p>
  
  <p>But since that designer needs to modify the properties of the selected <code>DelayComposite</code>
  in the designer, I have to pass this instance to it. That is why the constructor looks lie this:</p>
  
  <pre><code>public DelayCompositeDesigner(DelayComposite CompositeObject)
  {
      InitializeComponent();
  
      compositeObject = CompositeObject;
  }
  </code></pre>
  
  <p>Suggestions are welcome</p>
  
  <hr>
  
  <p>@VolkerK</p>
  
  <p>The result of your code is this:</p>
  
  <blockquote>
    <p>&lt;---- foo
    Vialis.LightLink.Controller.Scenarios.Composites.DelayCompositeDesignerVoid
    .ctor()
    Vialis.LightLink.Controller.Scenarios.Composites.DelayCompositeDesignerVoid
    .ctor(Vialis.LightLink.Controller.Scenarios.Composites.DelayComposite)
    param:Vialis.LightLink.Controller.Scenarios.Composites.DelayComposite
    foo ----></p>
  </blockquote>
  
  <hr>
  
  <p>Leppie, you were correct, I had for some reason referenced the Composites assembly in my UI application... which is not something I should have done as I was loading it at runtime. The following code works:</p>
  
  <pre><code>object composite = Activator.CreateInstance(item.CompositType,(byte)205);
                      var designer = Activator.CreateInstance(designerAttribute.Designer, composite);
  </code></pre>
  
  <p>As you can see the code does not have knowledge of the <code>DelayComposite</code> type.</p>
  
  <p>This solves the current problem, but introduces many new ones for what I want to achieve,
  either way thank you and thank you to everyone who has replied here.</p>
  
  <hr>
  
  <p>As for the following code, suggested by multiple people:</p>
  
  <pre><code>var designer = Activator.CreateInstance(
      designerAttribute.Designer, 
      new object[] { new DelayComposite(4) } 
  );
  </code></pre>
  
  <p>The <code>Activator.CreateInstance</code> has a signature that looks like this:</p>
  
  <pre><code>Activator.CreateInstance(Type type, params object[] obj)
  </code></pre>
  
  <p>So it should accept my code, but I will try the suggested code</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I've tried this as suggested:</p>
  
  <pre><code>var designer = Activator.CreateInstance(designerAttribute.Designer, new object[] { new DelayComposite(4)});
  </code></pre>
  
  <p>The result is the same.</p>