title: Why does implementing an interface on a subclass of EventSource throw an exception at runtime?
body: <p>I'm trying to use <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb968803.aspx" rel="noreferrer">Event Tracing for Windows (ETW)</a> in my .NET application via the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.tracing.eventsource.aspx" rel="noreferrer">EventSource</a> class that was included in .NET 4.5. I'm subclassing <code>EventSource</code> as <code>MyEventSource</code> and trying to implement an interface <code>IMyEventSource</code> (for mocking purposes) as follows:</p>
  
  <pre><code>public interface IMyEventSource
  {
    void Test();
  }
  
  public class MyEventSource : EventSource, IMyEventSource
  {
    public static MyEventSource Log = new MyEventSource();
  
    [Event(1)]
    public void Test()
    {
      this.WriteEvent(1);
    }
  }
  </code></pre>
  
  <p>When I run <a href="http://www.microsoft.com/en-us/download/details.aspx?id=28567" rel="noreferrer">PerfView</a> and execute this code, I get an <code>IndexOutOfRangeException</code> on the call to <code>WriteEvent</code>. If I remove the interface by modifying the code...</p>
  
  <pre><code>public class MyEventSource : EventSource
  {
    public static MyEventSource Log = new MyEventSource();
  
    [Event(1)]
    public void Test()
    {
      this.WriteEvent(1);
    }
  }
  </code></pre>
  
  <p>...then everything works just fine.</p>
  
  <p>Here is the code I used for testing in both cases:</p>
  
  <pre><code>static void Main(string[] args)
  {
    MyEventSource.Log.Test();
  }
  </code></pre>
  
  <p>Why does my subclass of <code>EventSource</code> break if it simply implements an interface?</p>
  
  <p>Here is a <a href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/fe1fb147-d6f4-4cfe-be45-29b74cc7fa36/#851d469f-880d-475d-997a-a3dd1490dfaa" rel="noreferrer">related post</a>.</p>