title: Unity Interception: Interface interception for an interface with events
body: <p>I am trying to use unity interception to intercept exceptions. I defined an interface and a class that implements that Interface.</p>
  
  <p>I am trying to use InterfaceInterception, but Unity is throwing an exception that the type is not interceptable. I have checked my class and the only difference from other classes that are successfully intercepted is that this class and the interface declare some event.
  If I use VirtualMethodInterception, Unity does not throw an exception.</p>
  
  <p>I am using c#</p>
  
  <p>Why is VirtualMethodInterceptor working and why is the InterfaceInterceptor not working?</p>
  
  <p>Following is a simplification of actual code.</p>
  
  <pre class="lang-cs prettyprint-override"><code>public interface IInterfaceToBeInterceptable : IDisposable
  {
      event EventHandler&lt;ItemSavedEventArgs&gt; ItemSaved;
  
      event EventHandler&lt;GenericEventArgs&lt;bool&gt;&gt; JobWasCompleted;
  
      InvocationResult InvokeJob( JobInvocationParams invocationParams );
  }
  
  public class ClassToBeInterceptable : IInterfaceToBeInterceptable
  {
      public event EventHandler&lt;ItemSavedEventArgs&gt; ItemSaved;
  
      public event EventHandler&lt;GenericEventArgs&lt;bool&gt;&gt; JobWasCompleted;
  
      public InvocationResult InvokeJob( JobInvocationParams invocationParams )
      {
          // Implementation
      }
  
      public void Dispose()
      {
          // Implementation
      }
  
      private static GetInfo()
  
      {
          // Implementation
      }
  }
  </code></pre>
  
  <p>and the unity configuration is </p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;register type="IInterfaceToBeInterceptable" mapTo="ClassToBeInterceptable"&gt;
       &lt;lifetime type="singleton" /&gt;
  
       &lt;interceptor type="InterfaceInterceptor" /&gt;
       &lt;interceptionBehavior type="Exceptionbehavior"  /&gt;
       &lt;interceptionBehavior type="LoggingBehaviour" /&gt;
    &lt;/register&gt;
  </code></pre>
  
  <p>The exception details are as follows</p>
  
  <p>Exception is: ArgumentException - The type ClassToBeInterceptable  is not interceptable.
  Parameter name: interceptedType</p>
  
  <p>EDIT :-</p>
  
  <p>This class is specified as dependency for another class and the above exception is thrown during build up of another class which has dependency on the "another" class ( or to be precise, interface of the "another" class).</p>