title: Get methods and attributes from dll assembly
body: <p>I'm trying to get a small plugin mechanism running by reflecting an dll file providing my class <code>Plugin</code> (implementing my <code>Plugin</code>-Interface shared among dll and main project / sorry for naming both the same) offering an attribute of type <code>string</code> and a main-method <code>activate</code>:</p>
  
  <p>Interface:</p>
  
  <pre><code>public interface Plugin
  {
      string pluginName{get;set;}
      void activate(System.Windows.Forms.Form main);
  }
  </code></pre>
  
  <p>dll class:</p>
  
  <pre><code>    public class Plugin : WhiteA.Plugin
          {
              public string pluginName{get;set;}
  
              public void activate(System.Windows.Forms.Form main){
                  //find the right form to modify it
                  IEnumerable&lt;System.Windows.Forms.ComboBox&gt; ie= GetControlsOfType&lt;System.Windows.Forms.ComboBox&gt;(main);
                  System.Windows.Forms.ComboBox cb=GetControlsOfType&lt;System.Windows.Forms.ComboBox&gt;(main).FirstOrDefault();
                  cb.Items.Add("Modification");
                  System.Windows.Forms.MessageBox.Show(cb.SelectedItem.ToString());
              }
  
              public static IEnumerable&lt;T&gt; GetControlsOfType&lt;T&gt;(System.Windows.Forms.Control root)
                  where T : System.Windows.Forms.Control
              {
                  var t = root as T;
                  if (t != null)
                      yield return t;
  
                  var container = root as System.Windows.Forms.ContainerControl;
                  if (container != null)
                      foreach (System.Windows.Forms.Control c in container.Controls)
                          foreach (var i in GetControlsOfType&lt;T&gt;(c))
                              yield return i;
              }
          }
  </code></pre>
  
  <p>So here comes the problem, there is no <code>type</code> named <code>"Plugin"</code> to be found in the assembly. Tried to get all types from all assemblies in the directory, get all methods/members/custom attributes from them, have them logged etc, but there is nothing of my class <code>Plugin</code> to be found, while the dll definitely is being found, as it doesn't return the <code>MessageBox</code>. </p>
  
  <pre><code>string[] files=new string[]{};
              string path="Error retrieving path";
              try{
                  path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                  files = System.IO.Directory.GetFiles(path, "*.dll");
              }catch(Exception exF){
  
              }
              if(files.Length&gt;0){
                  foreach (string dll in files){
                      try{
                          System.Reflection.Assembly sampleAssembly = System.Reflection.Assembly.LoadFrom(dll);
                          Type myType = sampleAssembly.GetType("Plugin");
                          System.Reflection.MethodInfo method = myType.GetMethod("activate");
                          object myInstance = Activator.CreateInstance(myType);
                          method.Invoke(myInstance, new object[]{this});
                      }catch(Exception exL){
  
                      }
                  }
              }else{
                  MessageBox.Show("No working plugins detected in " + path.ToString(), "Nothing to activate", MessageBoxButtons.OK,  MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
              }
  </code></pre>
  
  <p>I know my code probably looks really messy to you all - I think the last <code>try</code>-block is the only thing relevant here, wanted to put in the class itself and the interface for a little bit transparency though - and my english isn't perfect, but I hope someone can help me out finding my attribute+method in the assembly.</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <pre><code>                    try{
                          System.Reflection.Assembly sampleAssembly = System.Reflection.Assembly.LoadFrom(dll);
  
                          List&lt;Type&gt; list= sampleAssembly.GetTypes().Where(p =&gt;
                                               p.Namespace == dll &amp;&amp;
                                               p.Name.Contains("Plugin")
                                              ).ToList();
                          Type myType=list.FirstOrDefault();
  
                          //Type myType = sampleAssembly.GetType("Plugin");
                          System.Reflection.MethodInfo method = myType.GetMethod("activate");
                          object myInstance = Activator.CreateInstance(myType);
                          method.Invoke(myInstance, new object[]{this});
  
                      }
  </code></pre>
  
  <p>I did change it according to <a href="https://stackoverflow.com/questions/79693/getting-all-types-in-a-namespace-via-reflection/34869091#34869091">Getting all types in a namespace via reflection</a> 
  Still the same result, what did I do wrong?</p>