title: Instantiate class using reflection
body: <p>I have different class libraries that each implement an interface <code>IImportCharacter</code>. In my main app, the user selects a DLL and the app needs to check if the library implements the interface and then instantiate the class in the library which implements it. I'm trying to use reflection to do this but I keep getting:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'CustomCharacter.Ogre' to type
    'MainGame.IImportCharacter'.</p>
  </blockquote>
  
  <pre><code>Assembly assembly = assemblyPath;
  foreach (Type type in assembly.GetTypes())
  {
      IImportCharacter instance = null;
      if (type.GetInterface("IImportCharacter") != null)
      {
          //exception thrown at this line
          instance = (IImportCharacter)Activator.CreateInstance(type);
      }
  }
  </code></pre>
  
  <p>I've copied the same <code>IImportCharacter</code> file into the main project, otherwise the compiler complains it doesn't know what <code>IImportCharacter</code> is. I think this might be causing the problem since it's not the same one being dynamically loaded. How can I fix this?</p>