But it works on my PC!

The random thoughts of Richard Fennell on technology and software development

Access denied when running a command with InvokeProcess in a TFS team build

When you are trying to run a command line tool via the InvokeProcess activity in a TFS 2010 Team build you might see the somewhat confusing ‘Access denied’ error. There appears to be no more detail in the log.

I have found that this is usually down to a type on the filename property of the activity.

It should be set to something like

“c:\my tools\tool.exe”

but is actually set to

“c:\my tools”

i.e. it is set to the folder not the filename. An easy mistake to make of cutting and pasting paths in from batch files.

You cannot execute a folder, hence the access denied error. Simple but easy to miss.

No error detail when using VMPrep

When using VMPrep to setup a VM for use in a Lab Management system I got the error cross at the bottom of the dialog


Not too much help, usually there is a link to the log file or a message.

If you look in the log file in c:\user\[name]\Appdata\Roaming\LMInstaller.txt you see that the path to the Patches folder is invalid.

This is fixed by editing the VMPrepTool\VMPrepToolLibrary\Applications.XML file and correcting the path (which I had made a typo in)

Using Nuget and TFS Build 2010

At one of our recent events I was asked if I had any experience using Nuget within a TFS 2010 build. At the time I had not, but I thought it worth a look.

For those of you who don’t know Nuget is a package manager that provides a developer with a way to manage assembly references in a project for assemblies that are not within their solution. It is most commonly used to manage external commonly used assemblies such a nHibernate or JQuery but you can also use it manage your own internal shared libraries.

The issue the questioner had was that they had added references via Nuget to a project


Their project then contained a packages.config file that listed the Nuget dependencies. This was in the project root with the <project>.csproj file.

<?xml version="1.0" encoding="utf-8"?>
<packages>   <package id="Iesi.Collections" version="" />   <package id="NHibernate" version="" />

This packages.config  is part of the Visual Studio project and so when the project was put under source control so was it.

However, when they created a TFS build to build this solution all seems OK until the build ran, when they got a build error along the lines

Form1.cs (16): The type or namespace name 'NHibernate' could not be found (are you missing a using directive or an assembly reference?)
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (1490): Could not resolve this reference. Could not locate the assembly "Iesi.Collections". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (1490): Could not resolve this reference. Could not locate the assembly "NHibernate". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

Basically the solution builds locally but not on the build box, the assemblies referenced by Nuget are missing. A quick look at the directory structure show why. Nuget stores the assemblies it references in the solution folder, so you end up with

Solution Directory
      Packages – the root of the local cache of assemblies created by Nuget
      Project Directory

If you look in the <project>.csproj  file you will see a hint path pointing back up to this folder structure so that the project builds locally

<Reference Include="NHibernate">

The problem is that this folder structure is not known to the solution (just to Nuget), so this means when you add the solution to source control this structure is not added, hence the files are not there for the build box to use.

To fix this issue there are two options

  1. Add the folder to source control manually
  2. Make the build process aware of Nuget and allow it to get the files it needs as required.

For now lets just use the first option, which I like as in general in do want to build my projects against a known version of standard assemblies, so putting the assemblies under source control is not an issue for me. It allows me to easily go back to the specific build if I have to.

(A quick search with your search engine of choice will help with the second option, basically using the nuget.exe command line is the core of the solution)

To add the files to source control, I when into Visual Studio > Team Explorer > Source Control and navigated to the correct folder. I then pressed the add files button and added the whole Packages folder. This is where I think my questioner might have gone wrong. When you add the whole folder structure the default is to exclude .DLLs (and .EXEs)


If you don’t specifically add these files you will still get the missing references on the build, but could easily be thinking ‘ but I just added them!’, easy mistake to made, I know I did it.

Once ALL the correct files are under source control the build works as expected.

Seeing loads of ‘cannot load load assemblies’ errors when editing a TFS 2010 build process workflow

I have been following the process in the ALM Rangers build guide and in the Community Build Extensions to edit a build process workflow. Now I am sure this process was working until recently on my PC (but we all say that don’t we!), but of late I have found that when the .XAML workflow is loaded into Visual Studio I see loads of warning icons. If I check the list of imported namespaces many of them also have warning icons which if the icons are clicked they say the assembly cannot be found.


Now all these errors did not stop the editing process working. What I found was that if I made an edit in the graphical designer for the workflow or edited a property of an activity then my Visual Studio instance locked for about 20 seconds and it was fine (whilst there was loads of disk activity). I also noticed I got no intellisense when setting properties. Not a great position to be in but at least I could make some edits, if only slowly.

Using Process Monitor I could see that Visual Studio was scanning folders for the files when loading the XAML workflow, but not finding them.

The fix is actually simple. In the project that is being used as a container for the workflow being editing, make sure you reference the missing assemblies. These can be found in one of the following folders

  • C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
  • C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies
  • C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0

On my PC most of the assemblies were in the ReferenceAssemblies folder, not the first two, but on checking another PC at my office they were present in the PrivateAssemblies (which VS does scan)

Not sure why this has stopped working, what removed the files from my PrivateAssemblies folder, the only thing I can thing that I did was to install the Dev11 preview, But can’t see how this should have any effect.

Empty groups not being expanded in a combobox for a TFS work item

A common work item type (WIT) edit in TFS is to limit the list of names shown in a combo to the users assigned to the project i.e. the members of the Team Projects Contributors and Project Administrators groups.

This is done by editing the WIT either via your favourite XML editor or the Process Template Editor (part of the power tools). You edit the Allowedvalues for the field you wish to limit such as the Assigned To as shown below,


Which gives the following XML behind the scenes (for those using XML editors)

<ListRule filteritems="excludegroups">
  <LISTITEM value="[Project]\Contributors" />
  <LISTITEM value="[Project]\Project Administrators" />
  <LISTITEM value="Unassigned" />

Notice that Expand Items and Exclude Groups are checked. This means that the first two lines in the list will be expanded to contain the names in the groups, not the group names themselves.

A small gotcha here is that if either of the groups are empty you do see the group name in the combobox list, even with the Exclude Groups checked. Team Explorer does not expand an empty list to be a list with no entries, it show the group name. So you would see in the combo something like

  • [MyProject]\Contributors
  • John
  • Fred
  • Unassigned

where John and Fred as project administrators and the [MyProject]\Contributors group is empty.

This should not be a serious issue as in most cases why would you have a Team Project with no contributors or administrators? However it is conceivable with more complex security models you might see this issue. if so make sure each group in the list has at least one member, again if it does not have any members do you really need it?

Stupid gotchas on a SQL 2008 Reporting Services are why I cannot see the Report Builder Button

There is a good chance if you are using TFS that you will want to create some custom reports. You can write these in Reporting Services via BI Studio or Excel, but I wanted to use Report Builder, but could not see the Report Builder button on this Reporting Services menu


The problem was multi-levelled

First I had to give the user access to the Report Builder. This is done using folder property security. I chose to give this right to a user (along with browser rights) from the root of the reporting services site


But still no button. Forums and blog posts then talk about changing options on the ‘Site Settings’ menu, the above screenshots shows that this is also missing from the top right.

To get this menu option back, I had to run my browser as administrator and then this option appeared. Turns out that the TFS Setup user I was using  had not been made a Reporting Services site administrator, just a content administrator.

But still this was not enough, I also add to add users as System Users to allow the Reporting Services button to appears. So my final Site Settings > Security options were


Once all this was done I got my Report Build button and I could start to write reports.

What to do when your TFS build agent says it is ready, but the icon says it is not

When using TFS2010 It is possible for a build agent to appear to be ready (or so the status label says) but the icon stays in the off state.


This is usually due to a couple of broad categories of error, you can find out which by checking the Windows event log.

The build agent cannot communicate with the controller

In the event log you see something like

Service 'Default Agent - win7' had an exception:
Exception Message: There was no endpoint listening at
http://controller.mydomain.co.uk:9191/Build/v3.0/Services/Controller/1 that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. (type EndpointNotFoundException)

This should not happen too much within a corporate LAN, though it is always worth checking to make sure any PCs firewalls are not blocking the port used by the build service (9191).

However if you are trying to use build agents that are not directly on your LAN/AD (see this lovely clear blog post on how to set up using a non-domain joined build agent) there is a good chance you will not have DNS working as expected. So make sure the controller can resolve the name of the agent and vice versa. For me this meant editing HOST files and checking name resolved with good old PING.

Custom assemblies have un-resolved dependencies

Whilst writing documentation for the community extensions for TFS build I had the this problem. I had the custom assemblies path set for the build controller. This meant when the build agent starts it downloads any custom assemblies from the specified folder. Some the community extensions assume that the build agent has features/application installed such IIS or Visual Studio. I had assumed any missing dependencies would only show up when you tried to use a community activity in a build. However, this is not the case it seems. During the agent load some checks are made. In the event log I saw errors such as

Service 'Default Agent - win7' had an exception:
Exception Message: Problem with loading custom assemblies: Could not load file or assembly 'Microsoft.VisualStudio.Shell, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. (type Exception)


Service 'Default Agent - win7' had an exception:
Exception Message: Problem with loading custom assemblies: Could not load file or assembly 'Microsoft.Web.Administration, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. (type Exception)

To resolve these issues I installed the features and application on the agent needed by the build extensions. The other option would be remove the custom extension assemblies that had the dependencies, assuming you did not need them.

So hopefully this post should give you a pointer on fixing strange ‘has it started or not’ states that the build agent can get into

Bitlocker keeps asking for my recovery key after a change in my disk’s MBR

My development laptop is bitlocker’ed, and yours should be too. It provides a great and non-invasive way (assuming you have a TPM chip) to protect you and your clients data on a machine that is far to easy to steal or loose. However, whilst fiddling with Windows 8 I did trip myself up.

I have my PC setup for a boot to Windows 7 from a bitlocker’ed drive C with a non bitlocker’d drive D used to boot to Windows 2008 for demos (and hence no production data). To try out Windows 8 I added a new boot device, a boot from VHD partition. This edited the PC’s master boot record (MBR) and bitlocker did not like it. It thought the PC had a root kit or something similar to prompted me to enter a my bitlocker recovery key (which is 48 characters long) when I tried to boot to Windows 7. However, once this is done my bitlocker’ed Windows 7 partition worked find, but on each reboot I had to type the key in, bit of  pain. Removing the new VHD boot entry did not help, the MBR has still be edited, so bitlocker complained

The solution was actually easy, but took me a while to find as it does not seem to be clear in any documentation or via a search.

When the WIndows7 partition is booted open the control panel, select the bitlocker option and then suspend bitlocker, then restart it


This has the effect of telling the bitlocker system that you are accepting the current hardware/MBR setting are correct. After this the PC boots as expected

If I were being more sensible I would suspend bitlocker prior to any fiddling about with Windows 8 – but the bits from Build was just too tempting……….

Why can’t I see my custom work item types in Team Explorer?

If you are editing a TFS process template you have the choice editing XML files or using the Process Template Editor within the TFS 2010 PowerTools. Unfortunately neither is fool proof. You can make errors than means the revised template does not fully work.

The worst of these errors will be picked up when upload the process template to a Team project Collection as during this process the XML is validated.

However, this will not find everything. Today after uploading a new process template I found I could not see two of my revised work item type in the list when I tried to create a new work item.

The best way I found to work out the problem was to try to import the .WIT file (from your local copy of the process template) again using either the Visual Studio –> Tools –> Process Editor –> Work item Types –> Import from File, or the command line tool WITIMPORT

In my case I then got the far more useful error

Error importing work item type definition:

TF237094: Field name 'Priority' is used by the field 'Microsoft.VSTS.Common.Priority', so it cannot be used by the field 'MyNewProcess.Priority'.

This gave me much more information to fix my problem

‘Expected to find an element’ error when running VS2010 Database unit tests

If you use the database unit testing feature of VS2010 there is a good chance you will want to run these tests on more than one PC and probably the build server. The issue is that these different PC will need different deployment paths and SQL connection strings. Luckily there is a feature to address this, as detailed on MSDN. Basically the test runner swaps in a different config file based on either the PC name or user running the tests.

This all seems straight forward, but when I followed the process and ran my tests they failed


The most useful error is found if you get the test run details (the button highlighted in green). You can see that it found the file replacement config file but failed to parse it giving the error

An error occurred while reading file C:\…\TestResults\fred_PCNAME 2011-09-12 22_33_11\Out\buildbox.dbunittest.config : Expected to find an element.

[It is work noting here it is easy to forget to make sure the buildbox.dbunittest.config is deployed to the test folder as detailed on MSDN. If you forget this you get a file not found error not an ‘expected to find an element’ error]

So I checked my buildbox.dbunittest.config file to look for typos. The MSDN instructions say to copy the app.config and make your edits, but then goes onto mention after editing it should resemble.

       <DatabaseDeployment DatabaseProjectFileName="..\..\..\Sources\UnitTest\UnitTest\UnitTest.dbproj" Configuration="Debug" />
       <DataGeneration ClearDatabase="true" />
       <ExecutionContext Provider="System.Data.SqlClient" ConnectionString="Data Source=.\SQLEXPRESS;
                       Initial Catalog=UnitTestB;Integrated Security=True;Pooling=False" CommandTimeout="30" />
       <PrivilegedContext Provider="System.Data.SqlClient" ConnectionString="Data Source=.\SQLEXPRESS;
                       Initial Catalog=UnitTestB;Integrated Security=True;Pooling=False" CommandTimeout="30" />

It should NOT include the <?xml version="1.0" encoding="utf-8" ?>, <configuration> or <configSections> tags. This as been stressed in some forum posts. However even when I made sure my buildbox.dbunittest.config first line was <DatabaseUnitTesting> I still got the same error.

Turns out the issue was that I had leading white space before the <DatabaseUnitTesting>, once these were removed the test ran as expected.