title: GetType using string to interface
body: <p>I have created a DLL loader for Control DLL's (these controls have the same interface iControlPlugin), all is working great. However I now need to create a DLL loader for device drivers. I started looking at my Control Loader code and realised that the code is identical, except where the interface type is defined. I would therefore like to make my control loader function more generic so that it can be used for different interface types.</p>
  
  <p>I have modified the function so that it returns a dictionary, the problem I am having is that I do a check to make sure that the DLL file contains a matching type, in my case this is one of two interface types. But I always get null.</p>
  
  <p>This is my original, working function which is specifically targeted at one type (iLPPControlPlugin)</p>
  
  <pre><code>public Dictionary&lt;string, iLPPControlPlugin&gt; LoadPlugins(string folder)
  {
      /* Create a Dictionary object to store the loaded DLL's */
      Dictionary&lt;string, iLPPControlPlugin&gt; plugsins = new Dictionary&lt;string,iLPPControlPlugin&gt;();
  
      /* Get all the DLL files from the path specified */
      string[] files = Directory.GetFiles(folder, "*.dll");
  
      /* Go through each DLL... */
      foreach (string file in files)
      {
          /* Load the file, as an assembly. */
          Assembly assembly = Assembly.LoadFile(file);
  
          /* Get the type, can be more than one */
          var types = assembly.GetExportedTypes();
  
          /* For each type... */
          foreach (Type type in types)
          {
              if (type.GetInterfaces().Contains(typeof(iLPPControlPlugin)))
              {
                  /* Create an instance of the DLL */
                  object instance = Activator.CreateInstance(type);
  
                  /* As it is the correct type we know it will contain the "GetControlName" function.
                   * Call this to get the controls name. */
                  string controlName = ((iLPPControlPlugin)instance).GetControlName();
  
                  try
                  {
                      /* Try to add the instance to the dictionary list, using the control name as the key. */
                      plugsins.Add(controlName, instance as iLPPControlPlugin);
                  }
                  catch (ArgumentException)
                  {
                      /* Fails if there is already a DLL loaded with the same control name. This is a feature
                       * of the dictionary object. */
                      Console.WriteLine("Two or more Dll's have the same control name: " + controlName);
                  }
              }
          }
      }
      return plugsins;
  }
  </code></pre>
  
  <p>I have therefore changed the function, to be more generic, to this:</p>
  
  <pre><code>public Dictionary&lt;string, object&gt; LoadPlugins(string folder, string interfaceType)
  </code></pre>
  
  <p>To simplify the problem I currently ignore the parameter "interfaceType" and have hard coded the string, and check to this:</p>
  
  <pre><code>Type myType = Type.GetType("PluginInterface.iLPPControlPlugin");
  if (type.GetInterfaces().Contains(myType))
  </code></pre>
  
  <p>However the problem is that myType is always null. I have tried many different variations is no luck. I'm sure its going to be something simple but can anyone tell me what I am doing wrong. For information the PluginInterface namespace and iLPPControlPlugin class is a project within the solution.</p>
  
  <p>Many thanks,
  Chris</p>