spraints/git-tfs — Issue #93: null reference exception when retrieving work items
Author: luv2code
Created: 2011-10-11 16:46:43+00:00
State: open

Using the checkintool, the work items pane will say "__Object reference not set to instance of an object__", and it will not load any work items.

Using the checkin command, it lists the files that are going to be checked in, and then gives the message "__object reference not set to instance of an object__".

One of the first things I did was test the programmatic TFS interface using powershell:

```powershell
[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.TeamFoundation.Client”)
[void][System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.TeamFoundation.WorkItemTracking.Client”)

[psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer(“http://il01engtfs01:8080/TFS/TradeStationTPC”)
$WorkItemStore=$tfs.TfsTeamProjectCollection.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])

$wi = $WorkItemStore.GetWorkItem(18586)

echo $wi
```
This worked fine. printed all the details of my work item.

In git-tfs, _server.GetService() always returns null when T is WorkItemStore.

I debugged through the problem and the debugger threw an exception when I tried to inspect the workitemstore type. This is the exception:
__Mixed mode assembly is built against version 'v2.0.50727' of the runtime
and cannot be loaded in the 4.0 runtime without additional
configuration information.__

I used the answer from this SO question http://stackoverflow.com/questions/2455654/what-additional-configuration-is-necessary-to-reference-a-net-2-0-mixed-mode-a
I created config in the git-tfs.exe folder, and added the entry.

This fixed the issue. I can now pull work items with no problems.

I have no idea what the root cause is. Out of the four people here using git-tfs, mine was the only one with this issue. I am the only one with both VS2008 and VS2010; but I'm not certain if that has anything to do with it.. Why would my TFS assemblies be mixed mode and others would not?