title: Castle Windsor Interceptor
body: <p>I'm trying to use the code from this page, <a href="http://docs.castleproject.org/Windsor.Introduction-to-AOP-With-Castle.ashx" rel="nofollow">http://docs.castleproject.org/Windsor.Introduction-to-AOP-With-Castle.ashx</a> and register an interceptor in a fluent manner.
  But I get this error thrown. I've tried Castle Windsor versions from 2.5 to 3.3. So it must be something very basic in how interceptors are set up</p>
  
  <h2>Classes</h2>
  
  <pre><code>public interface ISomething
  {
      Int32 Augment(Int32 input);
      void DoSomething(String input);
      Int32 Property { get; set; }
  }
  
  class Something : ISomething
  {
      public int Augment(int input) {
          return input + 1;
      }
  
      public void DoSomething(string input) {
          Console.WriteLine("I'm doing something: " + input);
      }
  
      public int Property { get; set; }
   }
  
  public class DumpInterceptor : IInterceptor
  {
      public void Intercept(IInvocation invocation) {
          Console.WriteLine("DumpInterceptorCalled on method " +
              invocation.Method.Name);
          invocation.Proceed();
  
          if (invocation.Method.ReturnType == typeof(Int32)) {
              invocation.ReturnValue = (Int32)invocation.ReturnValue + 1;
          }
  
          Console.WriteLine("DumpInterceptor returnvalue is " +
              (invocation.ReturnValue ?? "NULL"));
      }     
  }
  </code></pre>
  
  <h2>Setup</h2>
  
  <pre><code>Console.WriteLine("Run 2 - configuration fluent");
  using (WindsorContainer container = new WindsorContainer())
  {
      container.Register(
          Component.For&lt;IInterceptor&gt;()
          .ImplementedBy&lt;DumpInterceptor&gt;()
          .Named("myinterceptor"));
      container.Register(
          Component.For&lt;ISomething&gt;()
          .ImplementedBy&lt;Something&gt;()
       .Interceptors(InterceptorReference.ForKey("myinterceptor")).Anywhere);
  
  
      ISomething something = container.Resolve&lt;ISomething&gt;(); //Offending row
  
      something.DoSomething("");
  
      Console.WriteLine("Augment 10 returns " + something.Augment(10));
  }
  </code></pre>
  
  <h2>Error</h2>
  
  <blockquote>
    <p>Type 'Castle.Proxies.ISomethingProxy' from
    assembly'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral,
    PublicKeyToken=null' is attempting to implement an inaccessible
    interface.</p>
  </blockquote>