Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 828441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:43:28+00:00 2026-05-15T03:43:28+00:00

I recently upgraded a C# project from .NET 3.5 to .NET 4. I have

  • 0

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 MethodBase instances. Its body looks like this:

return null == methods || methods.Count() == 0
    ? null
    : from method in methods
      let testAttribute = Attribute.GetCustomAttribute(method,
          typeof(TestMethodAttribute))
      where null != testAttribute
      select method;

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 [TestMethod]. Did something change with custom attributes in .NET 4?

Debugging, I found that the results of GetCustomAttributesData() on the test method gives a list of two CustomAttributeData which are described in Visual Studio 2010’s ‘Locals’ window as:

  1. Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute("myDLL.dll")
  2. Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute() — this is what I’m looking for

When I call GetType() on that second CustomAttributeData instance, however, I get {Name = "CustomAttributeData" FullName = "System.Reflection.CustomAttributeData"} System.Type {System.RuntimeType}. How can I get TestMethodAttribute out of the CustomAttributeData, so that I can extract test methods from a list of MethodBases?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:43:28+00:00Added an answer on May 15, 2026 at 3:43 am

    Silly mistake on my part: my test-method-extracting method was in a Class Library project that referenced Microsoft.VisualStudio.QualityTools.UnitTestFramework so that it could look for TestMethodAttribute as a custom attribute. When I upgraded my Solution from VS 2008 to VS 2010, the conversion process automatically updated references from Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0 to Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0 in my test projects. It did not update the reference in my Class Library project, however, so that was still pointing to the old UnitTestFramework reference. When I changed that project to point to the 10.0.0.0 library, my code below worked as expected:

    return null == methods || methods.Count() == 0
        ? null
        : from method in methods
          let testAttribute = Attribute.GetCustomAttribute(method,
              typeof(TestMethodAttribute))
          where null != testAttribute
          select method;
    

    Also, the code Jon suggested worked as well, once I updated the reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We recently upgraded a very large project from .NET framework 3.5 to 4, and
my company has recently upgraded from VS2005 to VS2010. We have a huge project
I have recently upgraded from CruiseControl .Net 1.4.3.x on our build machine to the
I recently upgraded my solution from .net framework 3.5 to 4.0. All good except
I have recently upgraded an existing java project from java 1.4 to 1.6 and
I recently upgraded one of my project from MVC2 to MVC3 and adjusted some
We just recently upgraded from VS2008 to VS2010. Our project compiles fine; but when
I just recently upgraded a VS2008/.NET 3.5 SP1 project to VS2010 and .NET 4.
I recently upgraded my project from Xcode 4.0.1 to Xcode 4.2 - and everything
I've recently upgraded my project from Visual Studio 2008 to Visual Studio 2010. By

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.