title: custom attribute changes in .NET 4
body: <p>I recently upgraded a C# project from .NET 3.5 to .NET 4.  I have a method that extracts all MSTest test methods from a given list of <code>MethodBase</code> instances.  Its body looks like this:</p>
  
  <pre><code>return null == methods || methods.Count() == 0
      ? null
      : from method in methods
        let testAttribute = Attribute.GetCustomAttribute(method,
            typeof(TestMethodAttribute))
        where null != testAttribute
        select method;
  </code></pre>
  
  <p>This worked in .NET 3.5, but since upgrading my projects to .NET 4, this code always returns an empty list, even when given a list of methods containing a method that is marked with <code>[TestMethod]</code>.  Did something change with custom attributes in .NET 4?</p>
  
  <p>Debugging, I found that the results of <code>GetCustomAttributesData()</code> on the test method gives a list of two <code>CustomAttributeData</code> which are described in Visual Studio 2010's 'Locals' window as:</p>
  
  <ol>
  <li><code>Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute("myDLL.dll")</code></li>
  <li><code>Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute()</code> -- this is what I'm looking for</li>
  </ol>
  
  <p>When I call <code>GetType()</code> on that second <code>CustomAttributeData</code> instance, however, I get <code>{Name = "CustomAttributeData" FullName = "System.Reflection.CustomAttributeData"}    System.Type {System.RuntimeType}</code>.  How can I get <code>TestMethodAttribute</code> out of the <code>CustomAttributeData</code>, so that I can extract test methods from a list of <code>MethodBase</code>s?</p>