C# 4.0 ‘dynamic’ doesn’t set ref/out arguments

This looks like it could be a bug – probably in DynamicObject. If you add a Wrap method to Proxy like this:

public void Wrap(ref int x, ref int y)
{
    target.Swap(ref x, ref y);
}

Then even though this is still called dynamically (i.e. the code in Main stays the same) the code works… so at least the general “how does a dynamic object work” layer supports pass-by-reference.

I suspect if this is indeed a bug in the DLR, it may be too late to fix for .NET 4 – but it’s worth reporting on Connect anyway so it can be fixed in a service pack. Alternatively, if this is a deliberate restriction/limitation, it should be clearly documented in MSDN (which it isn’t at the moment, as far as I can see).

Leave a Comment