Daniel pinged me today that he stumbled upon odd issue while trying to update Moq to use Castle DynamicProxy 2.2. I investigate a bit more and it appears to be one of these this-cannot-be-happening-select-is-broken situations.
When DynamicProxy tries to replicate an attribute on one method, its CustomAttributeData contains contradictory information. It happens only when running on .NET 4 (the method in question does not have the attribute in previous versions of BCL)
That’s the method in question in Reflector:
Here’s simplified code sample that reproduces the issue:
var method = typeof(HtmlInputText).GetMethod("GetDesignModeState", BindingFlags.Instance | BindingFlags.NonPublic);
Debug.Assert(method != null, "method != null");
var attributes = CustomAttributeData.GetCustomAttributes(method);
Debug.Assert(attributes.Count == 1, "attributes.Length == 1");
var attribute = attributes;
Debug.Assert(attribute.Constructor.GetParameters().Length == attribute.ConstructorArguments.Count, "This fails");
Now – what am I missing? Is this really bug in BCL v4 or am I doing something wrong here?
04-15-2010 8:10 PM