title: Using Castle.Windsor to register an interceptor for only the derived class, not the base class
body: <p>I am working on upgrading our project from .Net 2 to .Net4.5, at the same time I'm pushing as many references as I can to NuGet and making sure the versions are current.</p>
  
  <p>I am having a problem getting one of the tests to run</p>
  
  <p>The Test Classes:</p>
  
  <pre><code>        public class Person
      {
          public static int PersonBaseMethodHitCount { get; set; }
          public virtual void BaseMethod()
          {
              PersonBaseMethodHitCount = PersonBaseMethodHitCount + 1;
          }
          public static int PersonSomeMethodToBeOverriddenHitCount { get; set; }
          public virtual void SomeMethodToBeOverridden()
          {
              PersonSomeMethodToBeOverriddenHitCount = PersonSomeMethodToBeOverriddenHitCount + 1;
          }
      }
  
      public class Employee : Person
      {
          public static int EmployeeSomeMethodToBeOverriddenHitCount { get; set; }
          public override void SomeMethodToBeOverridden()
          {
              EmployeeSomeMethodToBeOverriddenHitCount = EmployeeSomeMethodToBeOverriddenHitCount + 1;
          }
          public static int EmployeeCannotInterceptHitCount { get; set; }
          public void CannotIntercept()
          {
              EmployeeCannotInterceptHitCount = EmployeeCannotInterceptHitCount + 1;
          }
  
          public virtual void MethodWithParameter(
              [SuppressMessage("a", "b"), InheritedAttribute, Noninherited]string foo)
          {
          }
      }
  
      public class MyInterceptor : IInterceptor
      {
          public static int HitCount { get; set; }
          public void Intercept(IInvocation invocation)
          {
              HitCount = HitCount + 1;
              invocation.Proceed();
          }
      }
  </code></pre>
  
  <p>The test (there is no setup for this fixture):</p>
  
  <pre><code>var container = new WindsorContainer();
          container.Register(Component.For&lt;MyInterceptor&gt;().ImplementedBy&lt;MyInterceptor&gt;());
          container.Register(
              Component
              .For&lt;Employee&gt;()
              .ImplementedBy&lt;Employee&gt;()
              .Interceptors(InterceptorReference.ForType&lt;MyInterceptor&gt;())
              .SelectedWith(new DerivedClassMethodsInterceptorSelector()).Anywhere);
          container.Register(Classes.FromAssembly(Assembly.GetExecutingAssembly()).Pick().WithService.FirstInterface());
  
          var employee = container.Resolve&lt;Employee&gt;();
          Person.PersonBaseMethodHitCount = 0;
          Person.PersonSomeMethodToBeOverriddenHitCount = 0;
          Employee.EmployeeCannotInterceptHitCount = 0;
          Employee.EmployeeSomeMethodToBeOverriddenHitCount = 0;
          MyInterceptor.HitCount = 0;
          employee.BaseMethod();
          Assert.That(Person.PersonBaseMethodHitCount, Is.EqualTo(1));
          // The BaseMethod was not overridden in the derived class so the interceptor should not have been called.
          Assert.That(MyInterceptor.HitCount, Is.EqualTo(0));
  
          Person.PersonBaseMethodHitCount = 0;
          Person.PersonSomeMethodToBeOverriddenHitCount = 0;
          Employee.EmployeeCannotInterceptHitCount = 0;
          Employee.EmployeeSomeMethodToBeOverriddenHitCount = 0;
          MyInterceptor.HitCount = 0;
          employee.SomeMethodToBeOverridden();
          Assert.That(Person.PersonSomeMethodToBeOverriddenHitCount, Is.EqualTo(0));
          Assert.That(Employee.EmployeeSomeMethodToBeOverriddenHitCount, Is.EqualTo(1));
          Assert.That(MyInterceptor.HitCount, Is.EqualTo(1)); //The test errors out on this line
  
          Person.PersonBaseMethodHitCount = 0;
          Person.PersonSomeMethodToBeOverriddenHitCount = 0;
          Employee.EmployeeCannotInterceptHitCount = 0;
          Employee.EmployeeSomeMethodToBeOverriddenHitCount = 0;
          MyInterceptor.HitCount = 0;
          employee.CannotIntercept();
          Assert.That(Employee.EmployeeCannotInterceptHitCount, Is.EqualTo(1));
          Assert.That(MyInterceptor.HitCount, Is.EqualTo(0));
  </code></pre>
  
  <p>I added a comment to denote where the test fails.</p>
  
  <p>So far as I can tell the problem is arising  in the DerivedClassMethodsInterceptorSelector</p>
  
  <p>Selector:</p>
  
  <pre><code>public class DerivedClassMethodsInterceptorSelector : IInterceptorSelector
  {
      public IInterceptor[] SelectInterceptors(Type type, MethodInfo method, IInterceptor[] interceptors)
      {
          return method.DeclaringType != type ? new IInterceptor[0] : interceptors;
      }
  }
  </code></pre>
  
  <p>When it makes the comparison of types, the type variable is System.RuntimeType but should be Employee (at least this is my understanding).</p>
  
  <p><strong>EDIT:</strong> 
  This problem was occurring using Castle.Windsor and Castle.Core 3.2.1, After making NuGet install the 3.1.0 package the code works as expected.</p>
  
  <p>I am leaning towards this being a bug, but I could also just be a change in the logic.</p>