Cannot understand the behaviour of C# compiler while instantiating a class thru interface
<p>I have a class that implements an interface. The interface is </p>

<pre><code>public interface IRiskFactory
{
   void StartService();
   void StopService();
}
</code></pre>

<p>The class that implements the interface is </p>

<pre><code>public class RiskFactoryService : IRiskFactory
{
}
</code></pre>

<p>Now I have a console application and one window service.</p>

<p>From the console application if I write the following code</p>

<pre><code>static void Main(string[] args)
{
    IRiskFactory objIRiskFactory = new RiskFactoryService();
    objIRiskFactory.StartService();
    Console.ReadLine();
    objIRiskFactory.StopService();
}
</code></pre>

<p>It is working fine. However, when I mwrite the same piece of code in Window service</p>

<pre><code>public partial class RiskFactoryService : ServiceBase
{
    IRiskFactory objIRiskFactory = null;
    public RiskFactoryService()
    {
        InitializeComponent();
        objIRiskFactory = new RiskFactoryService(); &lt;- ERROR
    }

    /// &lt;summary&gt;
    /// Starts the service
    /// &lt;/summary&gt;
    /// &lt;param name="args"&gt;&lt;/param&gt;
    protected override void OnStart(string[] args)
    {
        objIRiskFactory.StartService();
    }

    /// &lt;summary&gt;
    /// Stops the service
    /// &lt;/summary&gt;
    protected override void OnStop()
    {
        objIRiskFactory.StopService();
    }
}
</code></pre>

<p>It throws error: <strong>Cannot implicitly convert type 'RiskFactoryService' to 'IRiskFactory'. An explicit conversion exists (are you missing a cast?)</strong></p>

<p>When I type cast to the interface type, it started working</p>

<pre><code>objIRiskFactory = (IRiskFactory)new RiskFactoryService();
</code></pre>

<p>My question is why so?</p>
