Technology Toolbox

Your technology Sherpa for the Microsoft platform

Jeremy Jameson - Founder and Principal

Search

Search

Bug: Visual Studio 2008 Code Metrics and Referenced Assemblies

Note
This post originally appeared on my MSDN blog:

Since I no longer work for Microsoft, I have copied it here in case that blog ever goes away.

Since I seem to be on a roll this morning with blogging, I figured I might as well get one more post in before moving on to my "day job."

During the process of authoring a different post earlier today, I stumbled across a bug while using the Code Metrics feature in Visual Studio 2008.

After clicking the Analyze menu, and then clicking Calculate Code Metrics for Solution, I encountered errors similar to the following for several projects in the solution:

An error occurred while calculating code metrics for target file 'E:\NotBackedUp\...' in project ... The following error was encountered while reading module 'Microsoft.SharePoint': Could not resolve type: T ObjectModel.
(Don't ask me what the '' character is supposed to mean -- I just copied and pasted this directly from Visual Studio.)

It turns out that this is a known bug in Visual Studio 2008 due to the default setting that allows dependant assemblies to be used in a project without explicitly referencing them.

The workaround is to explicitly add the dependant assemblies to the project.

Consider the following projects from my solution:

PublicationLibrary.Workspaces

References:

  • Microsoft.SharePoint
  • Microsoft.SharePoint.Security
  • System
  • System.Data
  • System.Web
  • System.Xml

PublicationLibrary.Workspaces.DeveloperTests (i.e. the corresponding unit tests project)

References:

  • Microsoft.SharePoint
  • PublicationLibrary.Workspaces
  • System
  • System.Data
  • System.Web
  • System.Xml

With these references, Visual Studio is able to successfully compile both projects. However, it was only able to successfully calculate code metrics on the PublicationLibrary.Workspaces project; attempting to calculate code metrics on the second project yielded the aforementioned error.

After explicitly referencing Microsoft.SharePoint.Security in the PublicationLibrary.Workspaces.DeveloperTests project, the error went away and I could view the code metrics for both projects.

Comments

  1. # re: Bug: Visual Studio 2008 Code Metrics and Referenced Assemblies

    January 17, 2011 6:58 PM
    Andreu

    Hi Jeremy.

    Just few days I've found the problem you described in this post and it works.. Thanks a lot.

    I only needed to search the Microsoft.Sharepoint.Security.dll that was not delivered with the project I'm auditing and once added as a reference the problem was solved.

    For another people with the same problem if helps I'm using vs team system 2008 /sharepoint 2007

    Cheers

  2. # VSTS Links - 03/09/2009

    March 8, 2009 6:02 PM
    teamsystemrocks.com

Add Comment

Optional, but recommended (especially if you have a Gravatar). Note that your email address will not appear with your comment.
If URL is specified, it will be included as a link with your name.

To prevent spam from being submitted, please select the following fruit: Cherries

Pear
Grapes
Strawberry
Cherries
Watermelon
Apple
 
Please add 7 and 2 and type the answer here: