title: Castle DynamicProxy - Failure when creating proxy involving a GTP used as a GTR
body: <p>OK, now I'm really confused.</p>
  
  <p>I originally had <a href="https://stackoverflow.com/questions/4382624/cant-get-rhinomocks-to-emit-a-mock-that-follows-the-generic-type-restriction-ru">this problem</a>, which is, according to posters, an issue with the version of Castle.DynamicProxy that's ILMerged into the latest Rhino.Mocks library. It has, according to several authorities on the subject, been fixed in the latest Castle, but that library has not made it into a new Rhino.Mocks. Most people are saying "just download the Rhino source and the latest Castle and build your own version".</p>
  
  <p>So, I did exactly that; I grabbed a ZIP of the Rhino trunk source from Ayende's GitHub, opened it up, and built it. Then, like a good little TDDer, I created a unit test to make sure my changes worked (because the latest Castle folds DynamicProxy into Core, requiring some significant referencing changes):</p>
  
  <pre><code>    [Test]
      public void MockOfInterfaceMethodWithInterfaceGTR()
      {
          var mock = mocks.DynamicMock&lt;ITestRestrictedInterface&gt;();
          Assert.NotNull(mock);
          Expect.Call(mock.TestMethod(new Object2())).IgnoreArguments().Return(5);
          mocks.ReplayAll();
          Assert.AreEqual(5, mock.TestMethod(new Object2()));
      }
  
  ...
  
  internal interface ITestGenericInterface&lt;TRest&gt; where TRest:IObject1
  {
      int TestMethod&lt;T&gt;(T input) where T : TRest;
  }
  
  internal interface ITestRestrictedInterface:ITestGenericInterface&lt;IObject2&gt; { }
  
  internal interface IObject1 { }
  internal interface IObject2:IObject1 { }
  
  internal class Object2:IObject2 { } 
  </code></pre>
  
  <p>The result, when run in my own production code with the latest released Rhino? Failure with the following message: </p>
  
  <blockquote>
    <p>System.TypeLoadException : Method 'TestMethod' on type
    'ITestRestrictedInterfaceProxy83ad369cdf41472c857f61561d434436' from
    assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral,
    PublicKeyToken=null' tried to implicitly implement an interface method
    with weaker type parameter constraints.</p>
  </blockquote>
  
  <p>...However, when I copy and paste this test into a fixture in the Rhino.Mocks.Tests project, without making any changes to referenced libraries, the test PASSES. I have made zero changes to the downloaded source. I have made ZERO changes to the test method and related interfaces/objects on both sides. I built a new Rhino.Mocks DLL (without IL-merging the Castle libs) and copied it with Castle libs back to my production solution, re-ran the test, and it still fails with the same message.</p>
  
  <p>WTF?</p>