控制台应用程序出错。 'System.ArgumentOutOfRangeException' 类型的未处理异常

Got error for console application. An unhandled exception of type 'System.ArgumentOutOfRangeException'

我正在尝试按照此查询 Team Foundation Server:

https://msdn.microsoft.com/library/bb130306.aspx

这是我的

TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(
   new Uri("http://server:8080/tfs/DefaultCollection"));
    WorkItemStore workItemStore = (WorkItemStore)tpc.GetService   (typeof(WorkItemStore));

            // Run a query.
            WorkItemCollection queryResults = workItemStore.Query(
               "Select [State], [Title] " +
               "From WorkItems " );

            // Run a saved query.
            QueryHierarchy queryRoot = workItemStore.Projects[0].QueryHierarchy;
            QueryFolder folder = (QueryFolder)queryRoot["Shared Queries"];
            QueryDefinition query = (QueryDefinition)folder["Active Bugs"];
            queryResults = workItemStore.Query(query.QueryText);
        //}

我收到错误:

 An unhandled exception of type 'System.ArgumentOutOfRangeException'   occurred in Microsoft.TeamFoundation.WorkItemTracking.Client.dll

Additional information: Specified argument was out of the range of valid values.

我添加了一个捕获异常,但我收到了这个错误:

Specified argument was out of the range of valid values.
Parameter name: index.

您的 workItemStore.Projects 必须为空或 null。