Trying to cast in implementation of Interface
<p>I am trying to implement a plugin system in C#, and for that I created the following classes and interfaces:</p>

<p>Included in both loader and plugin:</p>

<pre><code>interface IDevicePlugin {
    string GetName();
    string GetVersion();
}
</code></pre>

<p>Plugin code (compiles to .dll)</p>

<pre><code>public class DummyPlugin : IDevicePlugin {
        protected string name;
        protected string version;

        public string GetName() {
            return name;
        }
        public string GetVersion() {
            return version;
        }
  }
</code></pre>

<p>The code to load the plugin is as follows:</p>

<pre><code>IDevicePlugin thePlugin;
Assembly plugin = Assembly.LoadFrom("plugin.dll");

foreach (Type pluginType in plugin.GetTypes()) {
       if (pluginType.IsPublic &amp;&amp; !pluginType.IsAbstract) {
            Type typeInterface = pluginType.GetInterface("IDevicePlugin", true);
            if (typeInterface != null) {
                 // the plugin implements our IDevicePlugin interface
                 thePlugin =  (IDevicePlugin)Activator.
                         CreateInstance(plugin.GetType(pluginType.ToString()));
            }
       }
}
</code></pre>

<p>And this crashes with:</p>

<pre><code>Unable to cast object of type 'PluginTest.DummyPlugin' to type 'PluginTest.IDevicePlugin'.
</code></pre>
