title: C# Convert dynamic object to interface
body: <pre><code>namespace MyNameSpace
  {
      public interface IMyInterface
      {
          string GetMethod();
      }
      public class MyClass : IMyInterface
      {
         public string GetMethod()
         {}
      }
  }
  </code></pre>
  
  <p>//Main Program</p>
  
  <pre><code>var ruleClass = Activator.CreateInstance(Assembly.GetExecutingAssembly().FullName, "MyNameSpace.MyClass"); 
  if( ruleClass != null)
  {
     IMyInterface myClass = (IMyInterface)ruleClass;
     //throws exception. 
  }
  </code></pre>
  
  <p>How can I convert <code>ruleClass</code> to <code>IMyInterface</code> type so that I can call specific methods in it?</p>