Clay and Castle Windsor 2.5

I've just downloaded the dynamic object framework Clay and am running into issues regarding castle project versions. Clay uses functionality from v2.0 of "castle" whilst I have a project which has been started referencing v2.5. Needless to say just to make matters more interesting I'm a complete beginner in all things "Castle" and IoC.

The real problem is that upgrading the references within clay solution results in a depreciated method warning. Regardless of whether you supress the method or not, the provided unit tests fail with a "Cannot perform runtime binding on a null reference" exception in the following code in "Intercept" of "InterfaceProxyBehavior":

       var invoker = BindInvoker(invocation);

The code that produces the run-time warning is in "CreateInstance" of "DefaultClayActivator":

       //var proxyType = _builder.CreateClassProxy(baseType, options);
       var proxyType = _builder.CreateClassProxyType(baseType, null, options);

As previously stated I'm still a complete beginner with Castle Windsor and just starting out with IoC so haven't even come across the Proxy stuff yet. Frustratingly I have no idea what the error message is even telling me, or asking for.

Have anyone already ported Clay across to version 2.5 of the castle project, so know the steps needed. Or can any one with experience of this part of castle throw anymore light on the error and what I may need to do to resolve it.


I'm still not really any the wiser as to the functionality that is failing, but have had chance to revisit the code running it both with v2.0 (works) and v2.5 (breaks) in castle.core. Attached are two images of the debug information when it works and then when it breaks. The test that it fails on is below, I've indicated the call with a comment.

namespace ClaySharp.Tests {
    public class BinderFallbackTests {
    public void TestInvokePaths() {
        var dynamically = ClayActivator.CreateInstance<Alpha>(new IClayBehavior[] { 
            new InterfaceProxyBehavior(), 
            new AlphaBehavior() 
        Alpha statically = dynamically;
        IAlpha interfacially = dynamically;

        Assert.That(dynamically.Hello(), Is.EqualTo("World-"));
        Assert.That(statically.Hello(), Is.EqualTo("World-"));
        Assert.That(interfacially.Hello(), Is.EqualTo("World-"));  // <- Fails on this call

        Assert.That(dynamically.Foo(), Is.EqualTo("Bar-"));
        Assert.That(interfacially.Foo(), Is.EqualTo("Bar-"));

        Assert.Throws<RuntimeBinderException>(() => dynamically.MissingNotHandled());

This is the debug information when using v2.5 of castle.core and the exception is thrown:

This is the debug information using v2.0 of castle.core (which works) for the same call / line that causes the problem with v2.5


I have never used this Clay thing, so all stuff below is based on assumptions.

The error message from BindInvoker is not a Castle error, but I'm guessing it's happening because the invoker is trying to bind to invocation target of the proxy which in DynamicProxy 2.1 used to have a value in some cases, which was wrong, and later versions 2.2 and 2.5 fixed that but it was a breaking change that you're now experiencing.

The other error message is telling you

Use CreateClassProxyType method instead.

Which is the other method you commented out. What's not obvious here?

It seems I fixed this. (all tests passing)

See the workitem on codeplex I created and the changes I pushed to my fork:

Some nice tutorials on Clay dynamic objects:

  • Malleable C# dynamic objects Part 1 Link

  • Malleable C# dynamic objects Part 2 Link.

Need Your Help

Prevent duplicate editing / Locking DB records while editing - single backend server

c# silverlight wcf session

Situation: multiple front-ends (e.g. Silverlight, ASP) sharing a single back-end server (WCF RIA or other web service).